Django InlineFormsets with programm logic or multiple use-Inlines?

Viewed 52

In my use-case I have 3 models, a house, room and chair. They are all intuitively in a 1:many-realtionship.
I want to reuse the inline on the house model to be used for 2 (consecutive) operations.

When I save a house I want to add rooms to it, and for each room the number of chairs that would fit each individual room¸ Once I created the house with its rooms, I want to add chairs to each room, but not more then the number of chairs that would fit into those individual rooms.

For convenience I'd like to use one Inline for adding rooms and setting the max number of chairs. I'd then like to use that Inline to assign chairs to the given house-rooms. I want to do those 2 operations while staying on 1 (web)page.

1 Answers

You can use the max_num option directly inside the inline.

From the docs:

This controls the maximum number of forms to show in the inline. This doesn’t directly correlate to the number of objects, but can if the value is small enough. See Limiting the number of editable objects for more information.

More info here: Limiting the number of editable objects

Related