I
I
ineveraskdfrths2020-05-04 16:04:11
Django
ineveraskdfrths, 2020-05-04 16:04:11

Django how to bind fk and m2m elements?

5eb012ad289f3220961301.png
Hello everyone, there are three tables product, category, department, product and category linked via Foreign key, because Each product belongs to only one category. Category and department are connected through manytomany, i.e. There can be several categories in one department. The question is, how to link (views) a product and a department, so that when you select a department, the page displays all the goods from the categories related to the department?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2020-05-04
@ineveraskdfrths

Product.objects.filter(category__office=current_office)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question