Reputation: 14783
I have a form looking like this:
class MarketingActionForm(forms.ModelForm):
contact = ManyToManyByLetter(Contact, field_name="first_name")
#contact = AjaxManyToManyField(Contact, DICT_LOOKUP)
class Meta:
model = MarketingAction
exclude = ('created_by',)
class Media:
js = (
settings.ADMIN_MEDIA_PREFIX + "js/SelectBox.js",
settings.ADMIN_MEDIA_PREFIX + "js/SelectFilter2.js",
settings.MEDIA_URL + "js/jquery.js",
settings.MEDIA_URL + "js/ajax_filtered_fields.js",
)
I process this form with a view to the template. Now I`m wondering why the Media class is not automatically processed in the template, at least it does not show up in the .html output.
Therefore i want to ask what i have to do in order that the media definitions will show up in the .html output.
I did not find it in the django .docs. Therefore i thought it will be processed automatically.
Upvotes: 9
Views: 3953
Reputation: 10896
You'll need to add {{form.media}}
in the template yourself. References to form media are not inserted automatically.
It would be very hard to do since entire html document including the <head>
section is to be typed by the template designer and django would have to guess where to insert the links if it were to attempt to do it automatically (it would be especially hard to guess correctly for the javascript media - if there are dependencies between scripts)
Upvotes: 11
Reputation: 6318
I believe the Media class is used in the admin, by classes which subclass admin.ModelAdmin
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-media-definitions
Upvotes: 0