C
C
cozstate2015-02-09 13:34:56
Django
cozstate, 2015-02-09 13:34:56

How to automatically set the value of the Inline field of the model in the admin panel?

You need to set the value of the ForeignKey field in the Inline admin model.
The value is the id of the main table.
I suspect that this should be done through the form, but I need a hint how exactly.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Kuzmichev, 2015-02-09
@Assargin

Doesn't Django do this automatically? This field is the link between the two models and no body movements should be required.
If you have, for example, the page for adding the Author entity in the admin panel, and on it there are inline with the Book entities, then when you add the author and several of his books, 1 record will be created in the database in the authors table, and the required number of records in the table of books associated with by this added author.

C
cozstate, 2015-02-09
@cozstate

The value for the Foreign field of the Inline model is the id of the third table referenced by the main table, sorry. This is not a link to the main model.
And the connection between Master/Detail, yes, it works right away, of course.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question