1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

newforms-admin: Fixed #6889 -- ModelForm nows supports media defined in the form.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7365 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Brian Rosner 2008-03-27 02:55:45 +00:00
parent 937c6e1054
commit 8cbcc7152b
2 changed files with 21 additions and 0 deletions

View File

@ -14,6 +14,7 @@ from util import ValidationError, ErrorList
from forms import BaseForm, get_declared_fields
from fields import Field, ChoiceField, IntegerField, EMPTY_VALUES
from widgets import Select, SelectMultiple, HiddenInput, MultipleHiddenInput
from widgets import media_property
from formsets import BaseFormSet, _formset_factory, DELETION_FIELD_NAME
__all__ = (
@ -226,6 +227,8 @@ class ModelFormMetaclass(type):
attrs)
new_class = type.__new__(cls, name, bases, attrs)
if 'media' not in attrs:
new_class.media = media_property(new_class)
declared_fields = get_declared_fields(bases, attrs, False)
opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None))
if opts.model:

View File

@ -912,4 +912,22 @@ True
u'...test3.png'
>>> instance.delete()
# Media on a ModelForm ########################################################
# Similar to a regular Form class you can define custom media to be used on
# the ModelForm.
>>> class ModelFormWithMedia(ModelForm):
... class Media:
... js = ('/some/form/javascript',)
... css = {
... 'all': ('/some/form/css',)
... }
... class Meta:
... model = PhoneNumber
>>> f = ModelFormWithMedia()
>>> print f.media
<link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/some/form/javascript"></script>
"""}