How to auto add detail into parent model in django admin

How to automatically add “componente” in “detalle relevamiento” according to the number of “pregunta” that the component has.

e.g. Based on IMG 1, if I have 4 “pregunta”, I should have 4 “componente”, one for each “pregunta”, as shown in IMG 2.

Im using django-smartselect for filter select options

Models:

Thanks !

I’m guessing you’re using an InlineModelAdmin in your model admin class for this.

These are built using model formsets. You can customize the construction of that formset to produce the results you want.
See Creating forms from models | Django documentation | Django and Model Form Functions | Django documentation | Django.

Also, the “per instance” customization of formsets is a topic discussed here previously. If you search this forum for formsets, you’ll find a number of posts on this particular topic that may be of help to you.

Edit:

As a side note, please do not create posts here with links to code elsewhere - especially links that are transient. One of the benefits of a forum such as this is the collected information over time. Having external links that will go away reduces the value of that information.

So for future questions, please copy/paste the relevant code in the body of the post, surrounded by lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted.

1 Like