mirror of
https://github.com/django/django.git
synced 2025-10-28 16:16:12 +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:
@@ -29,7 +29,7 @@ class Article(models.Model):
|
||||
return self.headline
|
||||
|
||||
__test__ = {'API_TESTS': """
|
||||
>>> from django.newforms import form_for_model
|
||||
>>> from django.newforms import form_for_model, BaseForm
|
||||
|
||||
>>> Category.objects.all()
|
||||
[]
|
||||
@@ -101,4 +101,13 @@ Traceback (most recent call last):
|
||||
...
|
||||
ValueError: The Category could not be created because the data didn't validate.
|
||||
|
||||
You can pass a custom Form class to form_for_model. Make sure it's a
|
||||
subclass of BaseForm, not Form.
|
||||
>>> class CustomForm(BaseForm):
|
||||
... def say_hello(self):
|
||||
... print 'hello'
|
||||
>>> CategoryForm = form_for_model(Category, form=CustomForm)
|
||||
>>> f = CategoryForm()
|
||||
>>> f.say_hello()
|
||||
hello
|
||||
"""}
|
||||
|
||||
Reference in New Issue
Block a user