In django, a formset is a layer of abstraction to working with multiple forms on the same page. It can be best compared to a data grid.
Questions tagged [formset]
585 questions
55
votes
7 answers
How to access data when form.is_valid() is false
When I have a valid Django form, I can access the data with form.cleaned_data. But how do I get at the data a user entered when the form is not valid i.e., form.is_valid is false.
I'm trying to access forms within a form set, so form.data seems to…

Greg
- 45,306
- 89
- 231
- 297
31
votes
7 answers
Django formset unit test
I can't run a unit test with formset.
I try to do a test:
class NewClientTestCase(TestCase):
def setUp(self):
self.c = Client()
def test_0_create_individual_with_same_adress(self):
post_data = {
…

Py.
- 365
- 1
- 4
- 10
30
votes
1 answer
Django formset_factory vs modelformset_factory vs inlineformset_factory
Forms can be complicated in Django. Formsets can make you want to quit Django. I'm at that point.
What are the different use cases and considerations of which one(s) to use?
I'm looking for some better guidance as to when to use each factory,…

chris Frisina
- 19,086
- 22
- 87
- 167
26
votes
2 answers
Django: Initializing a FormSet of custom forms with instances
Given the following models:
class Graph(models.Model):
owner = models.ForeignKey(User)
def __unicode__(self):
return u'%d' % self.id
class Point(models.Model):
graph = models.ForeignKey(Graph)
date =…

knipknap
- 5,934
- 7
- 39
- 43
23
votes
2 answers
Django: disallow can_delete on GenericStackedInline
I've built this model which contains a generic foreign key:
class MyModel(models.Model):
content_type = models.ForeignKey(ContentType, verbose_name=_('content type'))
object_id = models.PositiveIntegerField(_('object id'))
content_object…

user176455
- 685
- 1
- 10
- 21
16
votes
2 answers
Django Formset.is_valid() failing for extra forms
In my Django application application I have a formset that is created from a simple (not-model) form, with the extra=1 (to allow javasript to add more forms later on).
class SomeForm(forms.Form):
#some fields with required=False
length =…

Andriy Drozdyuk
- 58,435
- 50
- 171
- 272
15
votes
3 answers
django formset not validating because ID is required
MY view receives a model formset from the template, but it doesn't pass validation, claiming that ID is required. Al my use of forms until now has never brought up this problem, and I've never had to pass ID's around.
Here is a simplified version of…

Bigga
- 538
- 6
- 16
15
votes
2 answers
Django REST framework: save related models in ModelViewSet
I'm trying to figure out how to save related models using Django REST framework.
In my app I have a model Recipe with 2 related models: RecipeIngredient and RecipeStep. A Recipe object MUST have at least 3 related RecipeIngredient and 3 RecipeStep.…

daveoncode
- 18,900
- 15
- 104
- 159
12
votes
5 answers
Django and empty formset are valid
I have a little problem with the formset.
I must display several formsets in a page, and each formset has several forms.
So i did something like that :
#GET
for prod in products:
ProductFormSet =…

dancing
- 121
- 1
- 1
- 4
11
votes
4 answers
Django formset doesn't validate
I am trying to save a formset but it seems to be bypassing is_valid() even though there are required fields.
To test this I have a simple form:
class AlbumForm(forms.Form):
name = forms.CharField(required=True)
The view:
@login_required
def…

tsoporan
- 659
- 2
- 8
- 15
11
votes
2 answers
Django accessing formset data
I'm having difficulty accessing the data submitted through my formset. Here is my code:
Template:

apardes
- 4,272
- 7
- 40
- 66
10
votes
2 answers
Saving class-based view formset items with a new "virtual" column
I have a table inside a form, generated by a formset.
In this case, my problem is to save all the items after one of them is modified, adding a new "virtual" column as the sum of other two (that is only generated when displaying the table, not…

Abel Paz
- 573
- 7
- 20
10
votes
2 answers
Django find which form was submitted
I have 3 formsets in a single template. Only one would be visible at a given time (the other two are hidden entirely):

wernerfeuer
- 525
- 2
- 7
- 17
10
votes
2 answers
Django Formset without instance
In this Django Doc explain how to create a formset that allows you to edit books belonging to a particular author.
What I want to do is: Create a formset that allows you to ADD new book belonging to a NEW author... Add the Book and their Authors in…

panchicore
- 11,451
- 12
- 74
- 100
9
votes
1 answer