【发布时间】:2012-12-23 20:10:38
【问题描述】:
我在 Django 中有一个模型:
class Task(models.Model):
product = models.ForeignKey(Product)
content = models.OneToOneField(ContentDataSet)
如果我只想在标准下拉选择列表的用户/管理员中显示尚未分配的ContentDataSet 选项并已分配给此任务选项,我如何将选项limit_choices_to= 用于content 字段?
我尝试使用limit_choices_to = {'task__isnull':True},但在这种情况下,我看不到已经分配给此任务的content 选项。
limit_choices_to = models.Q(task__isnull=True) | models.Q(task=self) 不起作用,因为 self 未定义
【问题讨论】: