L
L
Leonid2019-12-11 11:13:31
Django
Leonid, 2019-12-11 11:13:31

How to design a model in Django?

Please advise on the following diagram. I need to make a menu with 3 hierarchies:
Home -> Category-> Product.
There are several types of goods. There is an abstract class and 2 subclasses with their own properties:

class Main()
   class Meta:
        abstract = True

class Tovar1(Main)
class Tovar2(Main)

each class from subordinates (Tovar1, Tovar2) can be included in several categories. Something I do not stick, how to add categories. At first I thought the Category class with ForeignKey on Product1 and Product2.
But at the same time, each record will require filling in AND Goods1 AND Goods2, which is not required.
Then I thought about Many, but something doesn’t appear as a scheme either ...
In general, I ask for help from the audience ;-)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2019-12-11
@bacon

At first I thought the Category class with ForeignKey on Product1 and Product2.

ForeignKey is set the other way around, the product must point to the category
PS I missed "may be included in several categories", then we change the ForeignKey to Many. And ForeignKey only if the product is in one category.

L
Leonid, 2019-12-11
@stilet69

In general, I did it through ManyToManyField

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question