summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-12-15 21:22:13 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-12-15 21:22:13 +0000
commit5cb093b033da3e4548142c2079431a4ac388532f (patch)
treeaeac0c28727da722b7ae366d901cd477a8ea7a5a /django
parent5efb9272e2490bd27d448447e8a750cbcfd3e7ae (diff)
newforms: Changed form_for_model() to ignore a field if its formfield() returns None, and changed AutoField.formfield() to return None
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4214 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/db/models/fields/__init__.py3
-rw-r--r--django/newforms/models.py7
2 files changed, 9 insertions, 1 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index a1537f0a94..fe317ac24f 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -375,6 +375,9 @@ class AutoField(Field):
super(AutoField, self).contribute_to_class(cls, name)
cls._meta.has_auto_field = True
+ def formfield(self):
+ return None
+
class BooleanField(Field):
def __init__(self, *args, **kwargs):
kwargs['blank'] = True
diff --git a/django/newforms/models.py b/django/newforms/models.py
index 6c01969001..58ed29e20f 100644
--- a/django/newforms/models.py
+++ b/django/newforms/models.py
@@ -10,7 +10,12 @@ __all__ = ('form_for_model', 'form_for_fields')
def form_for_model(model):
"Returns a Form class for the given Django model class."
opts = model._meta
- fields = SortedDictFromList([(f.name, f.formfield()) for f in opts.fields + opts.many_to_many])
+ field_list = []
+ for f in opts.fields + opts.many_to_many:
+ formfield = f.formfield()
+ if formfield:
+ field_list.append((f.name, formfield))
+ fields = SortedDictFromList(field_list)
return type(opts.object_name + 'Form', (BaseForm,), {'fields': fields, '_model_opts': opts})
def form_for_fields(field_list):