TabularInlines work fine if the relationship between two models is based on a foreign key.
For example, if there is a Restaurant model and a Pizza model (with a foreign key to Restaurant), it is easy to add Pizza to the Restaurant admin page as a TabularInline:
class RestaurantAdmin([url removed, login to view]):
inlines = (PizzaAdminInline,)
class PizzaAdminInline([url removed, login to view]):
model = Pizza
The problem I am having is if the relationship is a many-to-many relationship.
For example, let's say there is a M2M relationship between Pizza and Toppings. (Pizzas can have many toppings, and toppings can go on many pizzas).
If I create [url removed, login to view] code like this, the inline will only contain the M2M relationship (the Pizza_Toppings object):
class PizzaAdmin([url removed, login to view]):
inlines = (ToppingAdminInline,)
exclude = ('toppings',)
class ToppingAdminInline([url removed, login to view]):
model = [url removed, login to view]
I think if you've used Django Admin Inlines you know the exact problem I'm talking about.
So, I need you to create a custom view/form/whatever to make ToppingAdminInline display all the Topping Model fields, just like they would be displayed if the relationship was a foreign key rather than a many-to-many.
Please let me know if you have any questions.
10 freelancers are bidding on average $162 for this job
Your Requirement is Adding a restaurant For the a restaurant there will be multiple pizza For a Pizza there will be multiple toppings There will be three Models [url removed, login to view] [url removed, login to view] [url removed, login to view] This i Więcej