我想知道我如何设计我的决哥模型 以实现以下目标:
Road -> Category (required): Highway (select list)
Road -> Attribute (optional): Traffic -> Heavy + Moderate (checkboxes)
Road -> Attribute (optional): Condition -> Smooth + Rough + Average(checkboxes)
将人口贩运、文化条件、文化条件等纳入道路类, 与为每组选择设立单独的类别, 与创建通用属性类, 是否合理?
我如何将选择显示为复选框?
这一模式的最终目标是能够创建查询,如“无交通顺畅的高速公路它们>”等查询。
以下是我的尝试:
class Category(models.Model):
CATEGORY_CHOICES = (
( highway , Highway ),
( parkway , Parkway ),
)
name = models.CharField(max_length=1, choices=CATEGORY_CHOICES, blank=False)
class Road(models.Model):
name = models.TextField(blank=False)
TRAFFIC_CHOICES = (
( moderate , Moderate ),
( busy , Busy ),
)
traffic = models.CharField(max_length=1, choices=TRAFFIC_CHOICES)
CONDITION_CHOICES = (
( smooth , Smooth ),
( rough , Rough ),
( average , Average ),
)
condition = models.CharField(max_length=1, choices=CONDITION_CHOICES)