summaryrefslogtreecommitdiff
path: root/django/newforms
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-12-15 05:46:11 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-12-15 05:46:11 +0000
commit6001974e4501d7d8a7fcdfb11776bfb81d024754 (patch)
tree6e1cfb9b9f059e84414a7773149dce28b6761570 /django/newforms
parent0a7d8b18ff844edad75ac3b21fb89e479db4705a (diff)
newforms: Added initial implementation of form_for_model and form_for_fields
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4205 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms')
-rw-r--r--django/newforms/models.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/django/newforms/models.py b/django/newforms/models.py
index d99619c44a..6c01969001 100644
--- a/django/newforms/models.py
+++ b/django/newforms/models.py
@@ -1,13 +1,19 @@
"""
-Helper functions for creating Forms from Django models and database field objects.
+Helper functions for creating Form classes from Django models
+and database field objects.
"""
+from forms import BaseForm, DeclarativeFieldsMetaclass, SortedDictFromList
+
__all__ = ('form_for_model', 'form_for_fields')
def form_for_model(model):
- "Returns a Form instance for the given Django model class."
- raise NotImplementedError
+ "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])
+ return type(opts.object_name + 'Form', (BaseForm,), {'fields': fields, '_model_opts': opts})
def form_for_fields(field_list):
- "Returns a Form instance for the given list of Django database field instances."
- raise NotImplementedError
+ "Returns a Form class for the given list of Django database field instances."
+ fields = SortedDictFromList([(f.name, f.formfield()) for f in field_list])
+ return type('FormForFields', (BaseForm,), {'fields': fields})