Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Brian Rosner authored March 27, 2008
3  django/newforms/models.py
@@ -14,6 +14,7 @@
14 14
 from forms import BaseForm, get_declared_fields
15 15
 from fields import Field, ChoiceField, IntegerField, EMPTY_VALUES
16 16
 from widgets import Select, SelectMultiple, HiddenInput, MultipleHiddenInput
  17
+from widgets import media_property
17 18
 from formsets import BaseFormSet, _formset_factory, DELETION_FIELD_NAME
18 19
 
19 20
 __all__ = (
@@ -226,6 +227,8 @@ def __new__(cls, name, bases, attrs,
226 227
                     attrs)
227 228
 
228 229
         new_class = type.__new__(cls, name, bases, attrs)
  230
+        if 'media' not in attrs:
  231
+            new_class.media = media_property(new_class)
229 232
         declared_fields = get_declared_fields(bases, attrs, False)
230 233
         opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None))
231 234
         if opts.model:
18  tests/modeltests/model_forms/models.py
@@ -912,4 +912,22 @@ def __unicode__(self):
912 912
 u'...test3.png'
913 913
 >>> instance.delete()
914 914
 
  915
+# Media on a ModelForm ########################################################
  916
+
  917
+# Similar to a regular Form class you can define custom media to be used on
  918
+# the ModelForm.
  919
+
  920
+>>> class ModelFormWithMedia(ModelForm):
  921
+...     class Media:
  922
+...         js = ('/some/form/javascript',)
  923
+...         css = {
  924
+...             'all': ('/some/form/css',)
  925
+...         }
  926
+...     class Meta:
  927
+...         model = PhoneNumber
  928
+>>> f = ModelFormWithMedia()
  929
+>>> print f.media
  930
+<link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />
  931
+<script type="text/javascript" src="/some/form/javascript"></script>
  932
+
915 933
 """}

0 notes on commit 8cbcc71

Please sign in to comment.
Something went wrong with that request. Please try again.