Opened 16 years ago

Closed 16 years ago

#6889 closed (fixed)

Media not properly merged with admin widgets

Reported by: mrts Owned by: nobody
Component: contrib.admin Version: newforms-admin
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The functionality introduced in [7360] doesn't deal with media. If I provide media in my custom form, it breaks the admin js widgets.

For instance the following doesn't display the JavaScript date picker:

class Foo(models.Model):
    date = models.DateField()

# A class that adds TinyMCE to text fields.
class TinyMCEForm(forms.ModelForm):
    media = forms.Media(
        js = ['/site_media/js/tiny_mce/tiny_mce.js',
                '/site_media/js/add_editor.js'])

class FooAdmin(admin.ModelAdmin):
    form = admin_forms.TinyMCEForm
    save_on_top = True

admin.site.register(Foo, FooAdmin)

Leaving the custom form out of FooAdmin brings the date picker back.

Change History (3)

comment:1 by Brian Rosner, 16 years ago

Triage Stage: UnreviewedAccepted

I've discussed this with mrts in IRC. Will look into this as soon as I find time, unless mrts beats me too it ;)

comment:2 by Brian Rosner, 16 years ago

Ok, I have looked into this and discovered its reasoning. It was a good primer for me to really learn about the media code in newforms ;) There are a few things wrong among the poster's description and the newforms-admin code. First, the usage of media as shown in the description is incorrect. It is all clearly documented in the newforms.txt documentation. However, the correct usage still won't work correctly as a ModelForm doesn't honor Media on the class. One last minor note to mrts is that having a base form for simply a widget isn't really a great idea. While it will work, I would recommend making a custom widget as Media can be specified on widgets as well. Once again read the docs in the branch ;) I will commit my patch shortly.

comment:3 by Brian Rosner, 16 years ago

Resolution: fixed
Status: newclosed

(In [7365]) newforms-admin: Fixed #6889 -- ModelForm nows supports media defined in the form.

Note: See TracTickets for help on using tickets.
Back to Top