简体   繁体   中英

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)?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM