Changes between Version 16 and Version 17 of AddWYSIWYGEditor


Ignore:
Timestamp:
07/09/2008 10:10:48 AM (7 years ago)
Author:
Martin Diers <martin@…>
Comment:

Updated instructions for newforms-admin to use ModelForm

Legend:

Unmodified
Added
Removed
Modified
  • AddWYSIWYGEditor

    v16 v17  
    7373
    7474=== With newforms-admin ===
    75 '''With [wiki:NewformsAdminBranch newforms-admin]''', you have to use black magic, at the time of writing.
    76 
    77 If you look at [source:django/branches/newforms-admin/django/contrib/admin/options.py the ModelAdmin class], you'll note that there's a {{{media}}} property, which generates a
    78 new {{{Media}}} object each time you access the attribute. To get by that, we need to remake this property and "inject" our !JavaScript locations.
     75Since changeset [7365] you can now add a media definition to a new ModelForm instance and assign it to your ModelAdmin instance.
    7976
    8077{{{
    8178#!python
    82 class MyAdminOpts(admin.ModelAdmin):
    83      def _media(self):
    84          media = super(MyAdminOpts, self)._media()
    85          media.add_js([
    86              "http://path/to/tiny_mce.js",
    87              "http://path/to/textarea.js"])
    88          return media
    89      media = property(_media)
     79from django import newforms as forms
     80
     81class PageFormWithMedia(forms.ModelForm)
     82    class Media:
     83        js = ('/js/tiny_mce/tiny_mce.js',
     84              '/js/tiny_mce/textarea.js',)
     85
     86    class Meta:
     87        model = MyModel
     88
     89
     90class MyModelOptions(admin.ModelAdmin):
     91    form = PageFormWithMedia
     92
     93admin.site.register(MyModel, MyModelOptions)
     94
    9095}}}
    9196
Back to Top