~ubuntu-branches/ubuntu/quantal/python-django/quantal

« back to all changes in this revision

Viewing changes to docs/topics/forms/modelforms.txt

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2008-11-15 19:15:33 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20081115191533-xbt1ut2xf4fvwtvc
Tags: 1.0.1-0ubuntu1
* New upstream release:
  - Bug fixes.

* The tests/ sub-directory appaers to have been dropped upstream, so pull
  our patch to workaround the tests and modify the rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
    ===============================  ========================================
78
78
 
79
79
 
80
 
.. note::
 
80
.. versionadded:: 1.0
81
81
    The ``FloatField`` form field and ``DecimalField`` model and form fields
82
 
    are new in the development version.
 
82
    are new in Django 1.0.
83
83
 
84
84
As you might expect, the ``ForeignKey`` and ``ManyToManyField`` model field
85
85
types are special cases:
411
411
    <tr><th><label for="id_form-0-birth_date">Birth date:</label></th><td><input type="text" name="form-0-birth_date" id="id_form-0-birth_date" /><input type="hidden" name="form-0-id" id="id_form-0-id" /></td></tr>
412
412
 
413
413
.. note::
414
 
    One thing to note is that ``modelformset_factory`` uses ``formset_factory``
415
 
    and by default uses ``can_delete=True``.
 
414
    ``modelformset_factory`` uses ``formset_factory`` to generate formsets.
 
415
    This means that a model formset is just an extension of a basic formset
 
416
    that knows how to interact with a particular model.
416
417
 
417
418
Changing the queryset
418
419
---------------------
521
522
 
522
523
    def manage_authors(request):
523
524
        AuthorFormSet = modelformset_factory(Author)
524
 
        if request.POST == 'POST':
 
525
        if request.method == 'POST':
525
526
            formset = AuthorFormSet(request.POST, request.FILES)
526
527
            if formset.is_valid():
527
528
                formset.save()
559
560
    >>> author = Author.objects.get(name=u'Orson Scott Card')
560
561
    >>> formset = BookFormSet(instance=author)
561
562
 
562
 
More than one foriegn key to the same model
 
563
.. note::
 
564
    ``inlineformset_factory`` uses ``modelformset_factory`` and marks
 
565
    ``can_delete=True``.
 
566
 
 
567
More than one foreign key to the same model
563
568
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
564
569
 
565
570
If your model contains more than one foreign key to the same model you will