limit_choices_to外键中特定模型类的所有对象

时间:2010-10-28 23:17:06

标签: python django django-models

实施例

class Base():
     pass

class A(Base)
parent=models.Foreignkey("self", limit_choices_to=(all members of the B class)

class B(Base)
parent=models.Foreignkey("self", limit_choices_to=(all members of the A class)

limit_choices_to的查询语法是什么,只能得到 某一类的对象?)

1 个答案:

答案 0 :(得分:1)

这不会起作用吗?

class Base(Model):
    parent=models.Foreignkey("self")

    class Meta:
        abstract = True


class A(Base):
    parent=models.Foreignkey("B")

class B(Base):
    parent=models.Foreignkey("A")