Django

Code

Ticket #6889 (closed: fixed)

Opened 3 months ago

Last modified 3 months ago

Media not properly merged with admin widgets

Reported by: mrts Assigned to: nobody
Milestone: Component: Admin interface
Version: newforms-admin Keywords:
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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.

Attachments

Change History

03/25/08 17:51:13 changed by brosner

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

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

03/26/08 21:53:04 changed by brosner

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.

03/26/08 21:55:45 changed by brosner

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #6889 (Media not properly merged with admin widgets)




Change Properties
Action