Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 2 commits
  • 11 files changed
  • 0 commit comments
  • 1 contributor
View
1 django/forms/__init__.py
@@ -5,5 +5,6 @@
from django.core.exceptions import ValidationError # NOQA
from django.forms.fields import * # NOQA
from django.forms.forms import * # NOQA
+from django.forms.formsets import * # NOQA
from django.forms.models import * # NOQA
from django.forms.widgets import * # NOQA
View
2 django/forms/formsets.py
@@ -13,7 +13,7 @@
from django.utils.translation import ungettext, ugettext as _
-__all__ = ('BaseFormSet', 'all_valid')
+__all__ = ('BaseFormSet', 'formset_factory', 'all_valid')
# special field names
TOTAL_FORM_COUNT = 'TOTAL_FORMS'
View
3 django/forms/models.py
@@ -24,7 +24,8 @@
__all__ = (
'ModelForm', 'BaseModelForm', 'model_to_dict', 'fields_for_model',
'save_instance', 'ModelChoiceField', 'ModelMultipleChoiceField',
- 'ALL_FIELDS',
+ 'ALL_FIELDS', 'BaseModelFormSet', 'modelformset_factory',
+ 'BaseInlineFormSet', 'inlineformset_factory',
)
ALL_FIELDS = '__all__'
View
8 docs/ref/contrib/admin/index.txt
@@ -1544,7 +1544,7 @@ templates used by the :class:`ModelAdmin` views:
changelist page if :attr:`~ModelAdmin.list_editable` is used. To use a
custom formset, for example::
- from django.forms.models import BaseModelFormSet
+ from django.forms import BaseModelFormSet
class MyAdminFormSet(BaseModelFormSet):
pass
@@ -1860,14 +1860,14 @@ The ``InlineModelAdmin`` class adds:
.. attribute:: InlineModelAdmin.formset
- This defaults to :class:`~django.forms.models.BaseInlineFormSet`. Using
+ This defaults to :class:`~django.forms.BaseInlineFormSet`. Using
your own formset can give you many possibilities of customization. Inlines
are built around :ref:`model formsets <model-formsets>`.
.. attribute:: InlineModelAdmin.form
The value for ``form`` defaults to ``ModelForm``. This is what is passed
- through to :func:`~django.forms.models.inlineformset_factory` when
+ through to :func:`~django.forms.inlineformset_factory` when
creating the formset for this inline.
.. attribute:: InlineModelAdmin.extra
@@ -1938,7 +1938,7 @@ The ``InlineModelAdmin`` class adds:
.. method:: InlineModelAdmin.get_formset(self, request, obj=None, **kwargs)
- Returns a :class:`~django.forms.models.BaseInlineFormSet` class for use in
+ Returns a :class:`~django.forms.BaseInlineFormSet` class for use in
admin add/change views. See the example for
:class:`ModelAdmin.get_formsets`.
View
6 docs/ref/contrib/contenttypes.txt
@@ -497,13 +497,13 @@ information.
.. function:: generic_inlineformset_factory(model, form=ModelForm, formset=BaseGenericInlineFormSet, ct_field="content_type", fk_field="object_id", fields=None, exclude=None, extra=3, can_order=False, can_delete=True, max_num=None, formfield_callback=None, validate_max=False, for_concrete_model=True)
Returns a ``GenericInlineFormSet`` using
- :func:`~django.forms.models.modelformset_factory`.
+ :func:`~django.forms.modelformset_factory`.
You must provide ``ct_field`` and ``fk_field`` if they are different from
the defaults, ``content_type`` and ``object_id`` respectively. Other
parameters are similar to those documented in
- :func:`~django.forms.models.modelformset_factory` and
- :func:`~django.forms.models.inlineformset_factory`.
+ :func:`~django.forms.modelformset_factory` and
+ :func:`~django.forms.inlineformset_factory`.
.. versionadded:: 1.6
View
2 docs/ref/contrib/formtools/form-wizard.txt
@@ -166,7 +166,7 @@ This template expects a ``wizard`` object that has various items attached to
it:
* ``form`` -- The :class:`~django.forms.Form` or
- :class:`~django.forms.formsets.BaseFormSet` instance for the current step
+ :class:`~django.forms.BaseFormSet` instance for the current step
(either empty or with errors).
* ``steps`` -- A helper object to access the various steps related data:
View
2 docs/ref/forms/formsets.txt
@@ -2,7 +2,7 @@
Formset Functions
====================
-.. module:: django.forms.formsets
+.. module:: django.forms
:synopsis: Django's functions for building formsets.
.. function:: formset_factory(form, formset=BaseFormSet, extra=1, can_order=False, can_delete=False, max_num=None, validate_max=False, min_num=None, validate_min=False)
View
8 docs/ref/forms/models.txt
@@ -2,7 +2,7 @@
Model Form Functions
====================
-.. module:: django.forms.models
+.. module:: django.forms
:synopsis: Django's functions for building model forms and formsets.
.. function:: modelform_factory(model, form=ModelForm, fields=None, exclude=None, formfield_callback=None, widgets=None, localized_fields=None, labels=None, help_texts=None, error_messages=None)
@@ -52,11 +52,11 @@ Model Form Functions
Arguments ``model``, ``form``, ``fields``, ``exclude``,
``formfield_callback``, ``widgets``, ``localized_fields``, ``labels``,
``help_texts``, and ``error_messages`` are all passed through to
- :func:`~django.forms.models.modelform_factory`.
+ :func:`~django.forms.modelform_factory`.
Arguments ``formset``, ``extra``, ``max_num``, ``can_order``,
``can_delete`` and ``validate_max`` are passed through to
- :func:`~django.forms.formsets.formset_factory`. See :ref:`formsets` for
+ :func:`~django.forms.formset_factory`. See :ref:`formsets` for
details.
See :ref:`model-formsets` for example usage.
@@ -69,7 +69,7 @@ Model Form Functions
.. function:: inlineformset_factory(parent_model, model, form=ModelForm, formset=BaseInlineFormSet, fk_name=None, fields=None, exclude=None, extra=3, can_order=False, can_delete=True, max_num=None, formfield_callback=None, widgets=None, validate_max=False, localized_fields=None, labels=None, help_texts=None, error_messages=None)
Returns an ``InlineFormSet`` using :func:`modelformset_factory` with
- defaults of ``formset=``:class:`~django.forms.models.BaseInlineFormSet`,
+ defaults of ``formset=``:class:`~django.forms.BaseInlineFormSet`,
``can_delete=True``, and ``extra=3``.
If your model has more than one :class:`~django.db.models.ForeignKey` to
View
6 docs/releases/1.7.txt
@@ -326,7 +326,7 @@ Forms
customize the wording of the months displayed in the select widget.
* The ``min_num`` and ``validate_min`` parameters were added to
- :func:`~django.forms.formsets.formset_factory` to allow validating
+ :func:`~django.forms.formset_factory` to allow validating
a minimum number of submitted forms.
* The metaclasses used by ``Form`` and ``ModelForm`` have been reworked to
@@ -556,9 +556,9 @@ Miscellaneous
have a custom :class:`~django.core.files.uploadhandler.FileUploadHandler`
that implements ``new_file()``, be sure it accepts this new parameter.
-* :class:`ModelFormSet<django.forms.models.BaseModelFormSet>`’s no longer
+* :class:`ModelFormSet<django.forms.BaseModelFormSet>`’s no longer
delete instances when ``save(commit=False)`` is called. See
- :attr:`~django.forms.formsets.BaseFormSet.can_delete` for instructions on how
+ :attr:`~django.forms.BaseFormSet.can_delete` for instructions on how
to manually delete objects from deleted forms.
* Loading empty fixtures emits a ``RuntimeWarning`` rather than raising
View
52 docs/topics/forms/formsets.txt
@@ -3,7 +3,7 @@
Formsets
========
-.. module:: django.forms.formsets
+.. module:: django.forms
:synopsis: An abstraction for working with multiple forms on the same page.
.. class:: BaseFormSet
@@ -20,7 +20,7 @@ form::
You might want to allow the user to create several articles at once. To create
a formset out of an ``ArticleForm`` you would do::
- >>> from django.forms.formsets import formset_factory
+ >>> from django.forms import formset_factory
>>> ArticleFormSet = formset_factory(ArticleForm)
You now have created a formset named ``ArticleFormSet``. The formset gives you
@@ -35,7 +35,7 @@ would with a regular form::
As you can see it only displayed one empty form. The number of empty forms
that is displayed is controlled by the ``extra`` parameter. By default,
-:func:`~django.forms.formsets.formset_factory` defines one extra form; the
+:func:`~django.forms.formset_factory` defines one extra form; the
following example will display two blank forms::
>>> ArticleFormSet = formset_factory(ArticleForm, extra=2)
@@ -60,7 +60,7 @@ number of forms it generates from the initial data. Lets take a look at an
example::
>>> import datetime
- >>> from django.forms.formsets import formset_factory
+ >>> from django.forms import formset_factory
>>> from myapp.forms import ArticleForm
>>> ArticleFormSet = formset_factory(ArticleForm, extra=2)
>>> formset = ArticleFormSet(initial=[
@@ -90,11 +90,11 @@ list of dictionaries as the initial data.
Limiting the maximum number of forms
------------------------------------
-The ``max_num`` parameter to :func:`~django.forms.formsets.formset_factory`
+The ``max_num`` parameter to :func:`~django.forms.formset_factory`
gives you the ability to limit the maximum number of empty forms the formset
will display::
- >>> from django.forms.formsets import formset_factory
+ >>> from django.forms import formset_factory
>>> from myapp.forms import ArticleForm
>>> ArticleFormSet = formset_factory(ArticleForm, extra=2, max_num=1)
>>> formset = ArticleFormSet()
@@ -115,13 +115,13 @@ data forms will be displayed regardless. (No extra forms will be displayed.)
By default, ``max_num`` only affects how many forms are displayed and does not
affect validation. If ``validate_max=True`` is passed to the
-:func:`~django.forms.formsets.formset_factory`, then ``max_num`` will affect
+:func:`~django.forms.formset_factory`, then ``max_num`` will affect
validation. See :ref:`validate_max`.
.. versionchanged:: 1.6
The ``validate_max`` parameter was added to
- :func:`~django.forms.formsets.formset_factory`. Also, the behavior of
+ :func:`~django.forms.formset_factory`. Also, the behavior of
``FormSet`` was brought in line with that of ``ModelFormSet`` so that it
displays initial data regardless of ``max_num``.
@@ -132,7 +132,7 @@ Validation with a formset is almost identical to a regular ``Form``. There is
an ``is_valid`` method on the formset to provide a convenient way to validate
all forms in the formset::
- >>> from django.forms.formsets import formset_factory
+ >>> from django.forms import formset_factory
>>> from myapp.forms import ArticleForm
>>> ArticleFormSet = formset_factory(ArticleForm)
>>> data = {
@@ -254,8 +254,8 @@ Custom formset validation
A formset has a ``clean`` method similar to the one on a ``Form`` class. This
is where you define your own validation that works at the formset level::
- >>> from django.forms.formsets import BaseFormSet
- >>> from django.forms.formsets import formset_factory
+ >>> from django.forms import BaseFormSet
+ >>> from django.forms import formset_factory
>>> from myapp.forms import ArticleForm
>>> class BaseArticleFormSet(BaseFormSet):
@@ -306,11 +306,11 @@ number of forms should use custom formset validation.
~~~~~~~~~~~~~~~~
If ``validate_max=True`` is passed to
-:func:`~django.forms.formsets.formset_factory`, validation will also check
+:func:`~django.forms.formset_factory`, validation will also check
that the number of forms in the data set, minus those marked for
deletion, is less than or equal to ``max_num``.
- >>> from django.forms.formsets import formset_factory
+ >>> from django.forms import formset_factory
>>> from myapp.forms import ArticleForm
>>> ArticleFormSet = formset_factory(ArticleForm, max_num=1, validate_max=True)
>>> data = {
@@ -347,7 +347,7 @@ excessive.
.. versionchanged:: 1.6
The ``validate_max`` parameter was added to
- :func:`~django.forms.formsets.formset_factory`.
+ :func:`~django.forms.formset_factory`.
``validate_min``
~~~~~~~~~~~~~~~~
@@ -355,11 +355,11 @@ excessive.
.. versionadded:: 1.7
If ``validate_min=True`` is passed to
-:func:`~django.forms.formsets.formset_factory`, validation will also check
+:func:`~django.forms.formset_factory`, validation will also check
that the number of forms in the data set, minus those marked for
deletion, is greater than or equal to ``min_num``.
- >>> from django.forms.formsets import formset_factory
+ >>> from django.forms import formset_factory
>>> from myapp.forms import ArticleForm
>>> ArticleFormSet = formset_factory(ArticleForm, min_num=3, validate_min=True)
>>> data = {
@@ -383,12 +383,12 @@ deletion, is greater than or equal to ``min_num``.
.. versionchanged:: 1.7
The ``min_num`` and ``validate_min`` parameters were added to
- :func:`~django.forms.formsets.formset_factory`.
+ :func:`~django.forms.formset_factory`.
Dealing with ordering and deletion of forms
-------------------------------------------
-The :func:`~django.forms.formsets.formset_factory` provides two optional
+The :func:`~django.forms.formset_factory` provides two optional
parameters ``can_order`` and ``can_delete`` to help with ordering of forms in
formsets and deletion of forms from a formset.
@@ -401,7 +401,7 @@ Default: ``False``
Lets you create a formset with the ability to order::
- >>> from django.forms.formsets import formset_factory
+ >>> from django.forms import formset_factory
>>> from myapp.forms import ArticleForm
>>> ArticleFormSet = formset_factory(ArticleForm, can_order=True)
>>> formset = ArticleFormSet(initial=[
@@ -461,7 +461,7 @@ Default: ``False``
Lets you create a formset with the ability to select forms for deletion::
- >>> from django.forms.formsets import formset_factory
+ >>> from django.forms import formset_factory
>>> from myapp.forms import ArticleForm
>>> ArticleFormSet = formset_factory(ArticleForm, can_delete=True)
>>> formset = ArticleFormSet(initial=[
@@ -507,7 +507,7 @@ delete fields you can access them with ``deleted_forms``::
>>> [form.cleaned_data for form in formset.deleted_forms]
[{'DELETE': True, 'pub_date': datetime.date(2008, 5, 10), 'title': u'Article #1'}]
-If you are using a :class:`ModelFormSet<django.forms.models.BaseModelFormSet>`,
+If you are using a :class:`ModelFormSet<django.forms.BaseModelFormSet>`,
model instances for deleted forms will be deleted when you call
``formset.save()``.
@@ -516,7 +516,7 @@ model instances for deleted forms will be deleted when you call
If you call ``formset.save(commit=False)``, objects will not be deleted
automatically. You'll need to call ``delete()`` on each of the
:attr:`formset.deleted_objects
- <django.forms.models.BaseModelFormSet.deleted_objects>` to actually delete
+ <django.forms.BaseModelFormSet.deleted_objects>` to actually delete
them::
>>> instances = formset.save(commit=False)
@@ -535,8 +535,8 @@ accomplished. The formset base class provides an ``add_fields`` method. You
can simply override this method to add your own fields or even redefine the
default fields/attributes of the order and deletion fields::
- >>> from django.forms.formsets import BaseFormSet
- >>> from django.forms.formsets import formset_factory
+ >>> from django.forms import BaseFormSet
+ >>> from django.forms import formset_factory
>>> from myapp.forms import ArticleForm
>>> class BaseArticleFormSet(BaseFormSet):
... def add_fields(self, form, index):
@@ -560,7 +560,7 @@ management form inside the template. Let's look at a sample view:
.. code-block:: python
- from django.forms.formsets import formset_factory
+ from django.forms import formset_factory
from django.shortcuts import render_to_response
from myapp.forms import ArticleForm
@@ -639,7 +639,7 @@ a look at how this might be accomplished:
.. code-block:: python
- from django.forms.formsets import formset_factory
+ from django.forms import formset_factory
from django.shortcuts import render_to_response
from myapp.forms import ArticleForm, BookForm
View
44 docs/topics/forms/modelforms.txt
@@ -2,7 +2,7 @@
Creating forms from models
==========================
-.. module:: django.forms.models
+.. module:: django.forms
:synopsis: ModelForm and ModelFormset.
.. currentmodule:: django.forms
@@ -669,11 +669,11 @@ ModelForm factory function
--------------------------
You can create forms from a given model using the standalone function
-:func:`~django.forms.models.modelform_factory`, instead of using a class
+:func:`~django.forms.modelform_factory`, instead of using a class
definition. This may be more convenient if you do not have many customizations
to make::
- >>> from django.forms.models import modelform_factory
+ >>> from django.forms import modelform_factory
>>> from myapp.models import Book
>>> BookForm = modelform_factory(Book, fields=("author", "title"))
@@ -698,13 +698,13 @@ documentation.
Model formsets
==============
-.. class:: models.BaseModelFormSet
+.. class:: BaseModelFormSet
Like :doc:`regular formsets </topics/forms/formsets>`, Django provides a couple
of enhanced formset classes that make it easy to work with Django models. Let's
reuse the ``Author`` model from above::
- >>> from django.forms.models import modelformset_factory
+ >>> from django.forms import modelformset_factory
>>> from myapp.models import Author
>>> AuthorFormSet = modelformset_factory(Author)
@@ -725,8 +725,8 @@ with the ``Author`` model. It works just like a regular formset::
.. note::
- :func:`~django.forms.models.modelformset_factory` uses
- :func:`~django.forms.formsets.formset_factory` to generate formsets. This
+ :func:`~django.forms.modelformset_factory` uses
+ :func:`~django.forms.formset_factory` to generate formsets. This
means that a model formset is just an extension of a basic formset that
knows how to interact with a particular model.
@@ -743,7 +743,7 @@ queryset that includes all objects in the model (e.g.,
Alternatively, you can create a subclass that sets ``self.queryset`` in
``__init__``::
- from django.forms.models import BaseModelFormSet
+ from django.forms import BaseModelFormSet
from myapp.models import Author
class BaseAuthorFormSet(BaseModelFormSet):
@@ -810,7 +810,7 @@ Providing initial values
As with regular formsets, it's possible to :ref:`specify initial data
<formsets-initial-data>` for forms in the formset by specifying an ``initial``
parameter when instantiating the model formset class returned by
-:func:`~django.forms.models.modelformset_factory`. However, with model
+:func:`~django.forms.modelformset_factory`. However, with model
formsets, the initial values only apply to extra forms, those that aren't bound
to an existing object instance.
@@ -864,7 +864,7 @@ Limiting the number of editable objects
---------------------------------------
As with regular formsets, you can use the ``max_num`` and ``extra`` parameters
-to :func:`~django.forms.models.modelformset_factory` to limit the number of
+to :func:`~django.forms.modelformset_factory` to limit the number of
extra forms displayed.
``max_num`` does not prevent existing objects from being displayed::
@@ -899,7 +899,7 @@ Using a model formset in a view
Model formsets are very similar to formsets. Let's say we want to present a
formset to edit ``Author`` model instances::
- from django.forms.models import modelformset_factory
+ from django.forms import modelformset_factory
from django.shortcuts import render_to_response
from myapp.models import Author
@@ -933,7 +933,7 @@ the unique constraints on your model (either ``unique``, ``unique_together`` or
on a ``ModelFormSet`` and maintain this validation, you must call the parent
class's ``clean`` method::
- from django.forms.models import BaseModelFormSet
+ from django.forms import BaseModelFormSet
class MyModelFormSet(BaseModelFormSet):
def clean(self):
@@ -949,7 +949,7 @@ Using a custom queryset
As stated earlier, you can override the default queryset used by the model
formset::
- from django.forms.models import modelformset_factory
+ from django.forms import modelformset_factory
from django.shortcuts import render_to_response
from myapp.models import Author
@@ -1035,7 +1035,7 @@ primary key that isn't called ``id``, make sure it gets rendered.)
Inline formsets
===============
-.. class:: models.BaseInlineFormSet
+.. class:: BaseInlineFormSet
Inline formsets is a small abstraction layer on top of model formsets. These
simplify the case of working with related objects via a foreign key. Suppose
@@ -1053,15 +1053,15 @@ you have these two models::
If you want to create a formset that allows you to edit books belonging to
a particular author, you could do this::
- >>> from django.forms.models import inlineformset_factory
+ >>> from django.forms import inlineformset_factory
>>> BookFormSet = inlineformset_factory(Author, Book)
>>> author = Author.objects.get(name=u'Mike Royko')
>>> formset = BookFormSet(instance=author)
.. note::
- :func:`~django.forms.models.inlineformset_factory` uses
- :func:`~django.forms.models.modelformset_factory` and marks
+ :func:`~django.forms.inlineformset_factory` uses
+ :func:`~django.forms.modelformset_factory` and marks
``can_delete=True``.
.. seealso::
@@ -1072,12 +1072,12 @@ Overriding methods on an ``InlineFormSet``
------------------------------------------
When overriding methods on ``InlineFormSet``, you should subclass
-:class:`~models.BaseInlineFormSet` rather than
-:class:`~models.BaseModelFormSet`.
+:class:`~django.forms.BaseInlineFormSet` rather than
+:class:`~django.forms.BaseModelFormSet`.
For example, if you want to override ``clean()``::
- from django.forms.models import BaseInlineFormSet
+ from django.forms import BaseInlineFormSet
class CustomInlineFormSet(BaseInlineFormSet):
def clean(self):
@@ -1092,7 +1092,7 @@ See also :ref:`model-formsets-overriding-clean`.
Then when you create your inline formset, pass in the optional argument
``formset``::
- >>> from django.forms.models import inlineformset_factory
+ >>> from django.forms import inlineformset_factory
>>> BookFormSet = inlineformset_factory(Author, Book, formset=CustomInlineFormSet)
>>> author = Author.objects.get(name=u'Mike Royko')
>>> formset = BookFormSet(instance=author)
@@ -1110,7 +1110,7 @@ the following model::
length_in_months = models.IntegerField()
To resolve this, you can use ``fk_name`` to
-:func:`~django.forms.models.inlineformset_factory`::
+:func:`~django.forms.inlineformset_factory`::
>>> FriendshipFormSet = inlineformset_factory(Friend, Friendship, fk_name="from_friend")

No commit comments for this range

Something went wrong with that request. Please try again.