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:
parent
937c6e1054
commit
8cbcc7152b
@ -14,6 +14,7 @@ from util import ValidationError, ErrorList
|
|||||||
from forms import BaseForm, get_declared_fields
|
from forms import BaseForm, get_declared_fields
|
||||||
from fields import Field, ChoiceField, IntegerField, EMPTY_VALUES
|
from fields import Field, ChoiceField, IntegerField, EMPTY_VALUES
|
||||||
from widgets import Select, SelectMultiple, HiddenInput, MultipleHiddenInput
|
from widgets import Select, SelectMultiple, HiddenInput, MultipleHiddenInput
|
||||||
|
from widgets import media_property
|
||||||
from formsets import BaseFormSet, _formset_factory, DELETION_FIELD_NAME
|
from formsets import BaseFormSet, _formset_factory, DELETION_FIELD_NAME
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -226,6 +227,8 @@ class ModelFormMetaclass(type):
|
|||||||
attrs)
|
attrs)
|
||||||
|
|
||||||
new_class = type.__new__(cls, name, bases, 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)
|
declared_fields = get_declared_fields(bases, attrs, False)
|
||||||
opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None))
|
opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None))
|
||||||
if opts.model:
|
if opts.model:
|
||||||
|
@ -912,4 +912,22 @@ True
|
|||||||
u'...test3.png'
|
u'...test3.png'
|
||||||
>>> instance.delete()
|
>>> 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>
|
||||||
|
|
||||||
"""}
|
"""}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user