[Answer]-Insert to foreign key-linked table in django admin interface

1đź‘Ť

The trick is to add a ModelAdmin for Exercise.

The obvious consequence of this is that you’ll get a “top level” menu option to add exercises. However, a side effect is that everywhere that you have a model with a foreign key to exercise (like in your Segment inline), you’ll get a little green “plus” sign next to the Exercise foreign key selector. If you click on that plus, you’ll get a popup that will let you create a new Exercise. The popup will have the same layout as the “Add Exercise” page you get if you go through the top level menu, but without the navigation elements.

When you hit “save” on the new Exercise, the foreign key you clicked on will be updated to point at the newly added exercise instance.

👤freakboy3742

Leave a comment