forms.formsets.BaseFormSet.can_delete

BaseFormSet.can_delete Default: False Lets you create a formset with the ability to select forms for deletion: >>> from django.forms import formset_factory >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset_factory(ArticleForm, can_delete=True) >>> formset = ArticleFormSet(initial=[ ... {'title': 'Article #1', 'pub_date': datetime.date(2008, 5, 10)}, ... {'title': 'Article #2', 'pub_date': datetime.date(2008, 5, 11)}, ... ]) >&

forms.formsets.BaseFormSet.total_error_count()

BaseFormSet.total_error_count() [source] To check how many errors there are in the formset, we can use the total_error_count method: >>> # Using the previous example >>> formset.errors [{}, {'pub_date': ['This field is required.']}] >>> len(formset.errors) 2 >>> formset.total_error_count() 1 We can also check if form data differs from the initial data (i.e. the form was sent without any data): >>> data = { ... 'form-TOTAL_FORMS': '1', ...

forms.formsets.BaseFormSet

class BaseFormSet [source] A formset is a layer of abstraction to work with multiple forms on the same page. It can be best compared to a data grid. Let’s say you have the following form: >>> from django import forms >>> class ArticleForm(forms.Form): ... title = forms.CharField() ... pub_date = forms.DateField() 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.form

forms.formsets.BaseFormSet.can_order

BaseFormSet.can_order Default: False Lets you create a formset with the ability to order: >>> from django.forms import formset_factory >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset_factory(ArticleForm, can_order=True) >>> formset = ArticleFormSet(initial=[ ... {'title': 'Article #1', 'pub_date': datetime.date(2008, 5, 10)}, ... {'title': 'Article #2', 'pub_date': datetime.date(2008, 5, 11)}, ... ]) >>> for form in fo

forms.Form.use_required_attribute

Form.use_required_attribute New in Django 1.10. When set to True (the default), required form fields will have the required HTML attribute. Formsets instantiate forms with use_required_attribute=False to avoid incorrect browser validation when adding and deleting forms from a formset.

forms.Form.order_fields()

Form.order_fields(field_order) New in Django 1.9. You may rearrange the fields any time using order_fields() with a list of field names as in field_order.

forms.Form.prefix

Form.prefix You can put several Django forms inside one <form> tag. To give each Form its own namespace, use the prefix keyword argument: >>> mother = PersonForm(prefix="mother") >>> father = PersonForm(prefix="father") >>> print(mother.as_ul()) <li><label for="id_mother-first_name">First name:</label> <input type="text" name="mother-first_name" id="id_mother-first_name" required /></li> <li><label for="id_mother-last_na

forms.Form.non_field_errors()

Form.non_field_errors() This method returns the list of errors from Form.errors that aren’t associated with a particular field. This includes ValidationErrors that are raised in Form.clean() and errors added using Form.add_error(None, "...").

forms.Form.required_css_class

Form.required_css_class It’s pretty common to style form rows and fields that are required or have errors. For example, you might want to present required form rows in bold and highlight errors in red. The Form class has a couple of hooks you can use to add class attributes to required rows or to rows with errors: simply set the Form.error_css_class and/or Form.required_css_class attributes: from django.forms import Form class ContactForm(Form): error_css_class = 'error' required_cs

forms.Form.is_multipart()

Form.is_multipart() If you’re writing reusable views or templates, you may not know ahead of time whether your form is a multipart form or not. The is_multipart() method tells you whether the form requires multipart encoding for submission: >>> f = ContactFormWithMugshot() >>> f.is_multipart() True Here’s an example of how you might use this in a template: {% if form.is_multipart %} <form enctype="multipart/form-data" method="post" action="/foo/"> {% else %}