Awesome q2a theme

As in Django for the same field to do multiple values?

0 like 0 dislike
37 views
Good day!
I'm new, so don't be surprised if you see obvious mistakes in written.
Make the model of the goods in the online store. A product includes characteristics such as color or size, where there may be multiple values. I have 2 thoughts on how to do it:

1. To add to the model of the product and fill in as needed:
color1 = models.CharField(max_length=100, choices=ALL_COLORS, blank=True)
color2 = models.CharField(max_length=100, choices=ALL_COLORS, blank=True)

2. To do
colors = models.ManyToManyField(Color, verbose_name='colors')
And make in addition model of "Color" to make it work.

But the above is just a guess of a novice. The question is, how to do it properly?
by | 37 views

2 Answers

0 like 0 dislike
Both methods smack
1. It smacks of naming - well, you are fine to call color_bottom, color_top
2. Smacks of overengineering

If the products are homogeneous and they really only колор1 and колор2, better 1
If you have heterogeneous products, then you need json/eav
by
0 like 0 dislike
If you are using PostgreSQL, well suited to the use of JSONField. If another DBMS, you'll have to use EAV.
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
asked Apr 11, 2019 by serj2000
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users