mirror of
https://github.com/django/django.git
synced 2025-10-25 06:36:07 +00:00
newforms: Added optional 'form' parameter to form_for_model
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4220 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -16,8 +16,12 @@ def create(self, save=True):
|
||||
obj.save()
|
||||
return obj
|
||||
|
||||
def form_for_model(model):
|
||||
"Returns a Form class for the given Django model class."
|
||||
def form_for_model(model, form=None):
|
||||
"""
|
||||
Returns a Form class for the given Django model class.
|
||||
|
||||
Provide 'form' if you want to use a custom BaseForm subclass.
|
||||
"""
|
||||
opts = model._meta
|
||||
field_list = []
|
||||
for f in opts.fields + opts.many_to_many:
|
||||
@@ -25,7 +29,8 @@ def form_for_model(model):
|
||||
if formfield:
|
||||
field_list.append((f.name, formfield))
|
||||
fields = SortedDictFromList(field_list)
|
||||
return type(opts.object_name + 'Form', (BaseForm,), {'fields': fields, '_model': model, 'create': create})
|
||||
form = form or BaseForm
|
||||
return type(opts.object_name + 'Form', (form,), {'fields': fields, '_model': model, 'create': create})
|
||||
|
||||
def form_for_fields(field_list):
|
||||
"Returns a Form class for the given list of Django database field instances."
|
||||
|
||||
Reference in New Issue
Block a user