Skip to content
Advertisement

Where developers save choice options in Django?

For example i have a choice

COLORS = (
    ('red', 'Red'),
    ('blue', 'Blue'),
    ('yellow', 'Yellow'),
) 

Should i create a model like:

class Color(models.Model):
    color = models.CharField(...)

and create some color instances in django-admin or i need to declare CHOICE(above), where i save all colors(even if there are many colors)?

Advertisement

Answer

Let’s say you need to make a model product and this model has multiple colors. In this case you need to create a model for color.

In case every product has one color you can use choice.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement