A
A
Artyom Innokentiev2015-12-19 09:06:00
Django
Artyom Innokentiev, 2015-12-19 09:06:00

Should I create separate models for certain product categories in Django?

Let's say we have four categories of goods in the online store - Pen, Plasticine, Paper and Ruler.
What should you do - create one Product model or create five Pen, Plasticine, Paper, Ruler models and link them to the Product?
The disadvantage of the first option is that all the parameters of four products will be placed in the Product, while some products have unique parameters (Paper - size, paper weight, thickness, Ruler - length, division price, etc.). As a result - the Goods will be very loaded.
The disadvantage of the second option is that you will need to link the Pen, Plasticine, Paper and Ruler One to One with the Product in order to get unique IDs. The first option does not have this drawback.
How to be?
PS I'm leaning towards the second option, but I would really like to hear the opinions of experienced people. If there are other options - I will be only happy)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
nirvimel, 2015-12-19
@artinnok

First: definitely, one table for goods.
Secondly, category-specific features are defined as follows.

1. таблица Категории.
2. таблица ПризнакиКатегорий.
    - внешний ключ к Категории;
3. таблица ЗначенияПризнаков.
    - внешний ключ к ПризнакиКатегорий;
    - внешний ключ к Товыры;

V
Vladimir, 2015-12-19
@vintello

The phrase "create one Product model or create five models" should be read as "create one Product model AND create five models". in the Product model, add the Type field and write in it what type of product it is. depending on the type, take a subordinate table about the product.
and if you take out the properties of the product in a separate table and link it to the Product model and write properties according to the key-value type, it will be a bomb in general :) in general
, whoever likes it does so :)

D
denizen, 2015-12-20
@denizen

For such tasks, ready-made modules already exist. Look at this one for example .

Y
Yura Khlyan, 2015-12-21
@MAGistr_MTM

This is already implemented in Django-Oscar: model .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question