Changes between Version 10 and Version 11 of NewformsHOWTO


Ignore:
Timestamp:
02/18/2008 01:06:45 PM (7 years ago)
Author:
mrts
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NewformsHOWTO

    v10 v11  
    437437== Q: How do I add custom javascript? ==
    438438
    439 See #6619.
     439Override `form_add()` and `form_change()` in ModelAdmin.
     440
     441E.g. to add TinyMCE:
     442{{{
     443class MyModelAdmin(admin.ModelAdmin):
     444    save_on_top = True
     445    inlines = (MyOtherModelInline,)
     446    def form_add(self, req):
     447        class _AddForm(forms.Form):
     448            class Media:
     449                js = ['/site_media/js/tiny_mce/tiny_mce.js',
     450                        '/site_media/js/add_editor.js']
     451        if self.declared_fieldsets:
     452            fields = flatten_fieldsets(self.declared_fieldsets)
     453        else:
     454            fields = None
     455        return forms.form_for_model(self.model, form=_AddForm, fields=fields,
     456                           formfield_callback=self.formfield_for_dbfield)
     457}}}
     458
     459Note that this behaviour will change, a much more user-friendly way to control this will be added soon.
    440460
    441461== Q: How do I add custom validation? ==
    442462
    443 Use newforms as you would normally. Just look at the ```ModelAdmin``` class to see the hooks.
     463Again, override `form_add()` and `form_change()` in ModelAdmin.
Back to Top