summaryrefslogtreecommitdiff
path: root/django/newforms
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2008-01-02 16:57:53 +0000
committerJustin Bronn <jbronn@gmail.com>2008-01-02 16:57:53 +0000
commit7e322b5908bf5ec255c90c615d1b45b358ecee5f (patch)
tree3390dc70c5b4c4a8ff583308bd904eb749f97c04 /django/newforms
parentef0f46f1d0b9e41c811d3d6b833f1652ad46aec3 (diff)
gis: Merged revisions 6920-6989 via svnmerge from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@6990 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms')
-rw-r--r--django/newforms/models.py24
1 files changed, 11 insertions, 13 deletions
diff --git a/django/newforms/models.py b/django/newforms/models.py
index 17fd1cf2e2..fd0087a3b1 100644
--- a/django/newforms/models.py
+++ b/django/newforms/models.py
@@ -84,9 +84,8 @@ def form_for_model(model, form=BaseForm, fields=None,
determining the formfield for a given database field. It's a callable that
takes a database Field instance and returns a form Field instance.
"""
- warn("form_for_model is deprecated, use ModelForm instead.",
- PendingDeprecationWarning,
- stacklevel=3)
+ warn("form_for_model is deprecated. Use ModelForm instead.",
+ PendingDeprecationWarning, stacklevel=3)
opts = model._meta
field_list = []
for f in opts.fields + opts.many_to_many:
@@ -114,9 +113,8 @@ def form_for_instance(instance, form=BaseForm, fields=None,
takes a database Field instance, plus **kwargs, and returns a form Field
instance with the given kwargs (i.e. 'initial').
"""
- warn("form_for_instance is deprecated, use ModelForm instead.",
- PendingDeprecationWarning,
- stacklevel=3)
+ warn("form_for_instance is deprecated. Use ModelForm instead.",
+ PendingDeprecationWarning, stacklevel=3)
model = instance.__class__
opts = model._meta
field_list = []
@@ -149,10 +147,10 @@ def model_to_dict(instance, fields=None, exclude=None):
"""
Returns a dict containing the data in ``instance`` suitable for passing as
a Form's ``initial`` keyword argument.
-
+
``fields`` is an optional list of field names. If provided, only the named
fields will be included in the returned dict.
-
+
``exclude`` is an optional list of field names. If provided, the named
fields will be excluded from the returned dict, even if they are listed in
the ``fields`` argument.
@@ -187,7 +185,7 @@ def fields_for_model(model, fields=None, exclude=None, formfield_callback=lambda
``fields`` is an optional list of field names. If provided, only the named
fields will be included in the returned fields.
-
+
``exclude`` is an optional list of field names. If provided, the named
fields will be excluded from the returned fields, even if they are listed
in the ``fields`` argument.
@@ -214,9 +212,8 @@ class ModelFormOptions(object):
self.exclude = getattr(options, 'exclude', None)
class ModelFormMetaclass(type):
- def __new__(cls, name, bases, attrs):
- # TODO: no way to specify formfield_callback yet, do we need one, or
- # should it be a special case for the admin?
+ def __new__(cls, name, bases, attrs,
+ formfield_callback=lambda f: f.formfield()):
fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)]
fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter))
@@ -253,7 +250,8 @@ class ModelFormMetaclass(type):
base_model = getattr(base_opts, 'model', None)
if base_model and base_model is not opts.model:
raise ImproperlyConfigured('%s defines a different model than its parent.' % name)
- model_fields = fields_for_model(opts.model, opts.fields, opts.exclude)
+ model_fields = fields_for_model(opts.model, opts.fields,
+ opts.exclude, formfield_callback)
# fields declared in base classes override fields from the model
model_fields.update(declared_fields)
attrs['base_fields'] = model_fields