0
例limit_choice_to在一個ForeignKey特定模型CLASSE的所有對象
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查詢語法,只得到某一類的 對象?)
是的,我不認爲OP的代碼完全可以工作 - 'self'不是'Base',它是'A'或'B'。 – 2010-10-29 08:04:40
你是對的,我發佈的代碼是錯誤的。我想要的是類似sebplq的迴應(我不認爲這樣做或者是因爲你不能重寫子字段),但是維護父外鍵並僅過濾A和B類的可用選項。有沒有辦法做到這一點? – user443850 2010-10-29 16:08:28
class Base(Model): parent = models.Foreignkey(「self」) 當你這樣做並繼承時,self是Base和A或B.我想要的僅限於某些類名的選擇。管理員。 – user443850 2010-10-29 16:48:55