【发布时间】:2021-02-26 20:08:08
【问题描述】:
我是一个使用 django 的新手,我有一个无法解决的问题。 在我的 ServiceCreateView 中,我需要从下拉列表中选择具有字段 is_active = true 的对象汽车, 我怎样才能做到这一点?
class Car(models.Model):
brand = models.charfield(...)
is_active= models.BooleanField(default=True)
class Service(models.Model):
car = models.ForeingKey('Car'....)
name = models.Charfield()
class ServiceCreateView(CreateView):
model = Service
form = ServiceForm
...
如果我在 Car 模型中将字段 is_active 更改为 false,则不应显示在下拉列表中。 有人能把我引向正确的方向吗?
【问题讨论】:
标签: python django django-class-based-views