在models.py中我设置了选项。什么是让用户在下拉框中添加更多选项的最佳方式。
models.py
class Location(models.Model):
BUILDING_MATERIALS = (
('Brick', 'Brick'),
('Stone', 'Stone'),
('Breeze Block', 'Breeze Block'),
('Wooden', 'Wooden'),
('Pre Fap', 'Pre Fap'),
)
materials = models.CharField(max_length=12, choices=BUILDING_MATERIALS, null=False)
答案 0 :(得分:2)
然后,这是构建块的单独模型的标志:
class Material(models.Model):
name = models.CharField(max_length=12, null=False)
您Location
模型与Material
模型有关。如果location
只能有一个material
,则为ForeignKey
:
class Location(models.Model):
materials = models.ForeignKey(Material)