Questions tagged [inline-formset]

In Django, inline formsets are a small abstraction layer on top of model formsets. These simplify the case of working with related objects via a foreign key.

In Django, inline formsets are a small abstraction layer on top of model formsets. These simplify the case of working with related objects via a foreign key.

400 questions
60
votes
7 answers

django class-based views with inline model-form or formset

I have the following models: class Bill(models.Model): date = models.DateTimeField(_("Date of bill"),null=True,blank=True) class Item(models.Model): name = models.CharField(_("Name"),max_length=100) price =…
Hixi
  • 765
  • 1
  • 8
  • 9
49
votes
3 answers

Creating a model and related models with Inline formsets

[I have posted this at the Django users | Google Groups also.] Using the example in the inline formset docs, I am able to edit objects belonging a particular model (using modelforms). I have been trying to follow the same pattern for creating new…
chefsmart
  • 6,873
  • 9
  • 42
  • 47
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
27
votes
2 answers

how to limit django admin inline formsets

How do you limit the inline formset in django admin? Problem: I have a table A with 1 to n relationship with B. Table A should have at least one Table B item and a max of 5 Table B items.
ginad
  • 1,863
  • 2
  • 27
  • 42
18
votes
5 answers

inlineformset_factory create new objects and edit objects after created

In the django docs, there's an example of using inlineformset_factory to edit already created objects https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-an-inline-formset-in-a-view I changed the example to be this way: def…
KhoPhi
  • 9,660
  • 17
  • 77
  • 128
16
votes
5 answers

Django: How to change a field widget in a Inline Formset

I am new to Django and I think I am missing this in the docs. The problem is that in inline-formset I dont declare a form, just pass two models to construct it. I want to know how can I change a widget of a single field using inline formset?
nsbm
  • 5,842
  • 6
  • 30
  • 45
15
votes
3 answers

Django - CreateView not saving form with nested formset

I am trying to adapt an approach for saving nested formsets with main form using Django-Crispy-Forms layout feature but I can't save it. I am following this code example project but couldn't get formset validated to save data. I will be really…
Shazia Nusrat
  • 174
  • 1
  • 10
  • 36
15
votes
3 answers

Initial Data for Django Inline Formsets

I have put together a form to save a recipe. It makes use of a form and an inline formset. I have users with text files containing recipes and they would like to cut and paste the data to make entry easier. I have worked out how to populate the…
Sinidex
  • 473
  • 2
  • 6
  • 15
14
votes
1 answer

Django inline foreign key does not match parent primary key

I need some help getting past a django error using inline forms. I can't seem to figure this out. I could probably force-insert the eventID if I could figure out how to do that before it tries to validate. When I submit my form I get an error:…
codingJoe
  • 4,713
  • 9
  • 47
  • 61
11
votes
2 answers

OperationalError: no such table: django_content_type when using unittest

I'm trying to launch unittest for my django project and it returns me below error: ERROR: varys.users.tests.test_all_views (unittest.loader.ModuleImportFailure) ---------------------------------------------------------------------- ImportError:…
Diaus
  • 131
  • 1
  • 5
10
votes
6 answers

How to show different inlines depending of current object field value

Given a model named MainModel and a RelatedModel, where the later has a ForeignKey field to MainModel: class MainModel(models.Model): name = models.CharField(max_length=50) type = models.BooleanField() class RelatedModel1(models.Model): …
Armando Pérez Marqués
  • 5,661
  • 4
  • 28
  • 45
10
votes
3 answers

Inline formset in Django - removing certain fields

I need to create an inline formset which a) excludes some fields from MyModel being displayed altogether b) displays some some fields MyModel but prevents them from being editable. I tried using the code below, using values() in order to filter…
mermer
10
votes
1 answer

Django admin: Inline straight to second-level relationship

I have a three-levels Invoice model which I'd like to display on Django's admin area... in a "kind of special" way. Allow me to provide a bit of background: Each Invoice is conformed by several SubInvoice(s), and each SubInvoice is conformed by…
Savir
  • 17,568
  • 15
  • 82
  • 136
10
votes
1 answer

Testing InlineFormset clean methods

I have a Django project, with 2 models, a Structure and Bracket, the Bracket has a ForeignKey to a Structure (i.e. one-to-many, one Structure has many Brackets). I created a TabularInline for the admin site, so that there would be a table of…
Amandasaurus
  • 58,203
  • 71
  • 188
  • 248
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
1
2 3
26 27