Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 8cbcc7152b307b39bfd45a6b3e695bc5ab87b300 1 parent 937c6e1
@brosner brosner authored
View
3  django/newforms/models.py
@@ -14,6 +14,7 @@
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 @@ def __new__(cls, name, bases, attrs,
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
18 tests/modeltests/model_forms/models.py
@@ -912,4 +912,22 @@ def __unicode__(self):
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>
+
"""}
Please sign in to comment.
Something went wrong with that request. Please try again.