我有个模特
Application
带有字段
bank
,
mortgage
和
status
.相同
银行
和
抵押贷款
我只允许一个
application
具有
地位
与DRAFT不同。
class Application(..):
bank = ..
mortgage = ..
status = .. # draft, active, in_progress etc.
因此,可以有多个这样的应用程序:
# ok
Application(bank=1, mortgage=2, status='draft')
# ok, tuple mortgage and bank already exists but but status is draft
Application(bank=1, mortgage=2, status='draft')
# ok, tuple mortgage and bank already exists but status is active
Application(bank=1, mortgage=2, status='active')
# ERROR - tuple mortgage and bank already exists and there is already one object with non-draft status
Application(bank=1, mortgage=2, status='in_progress')
# ok - bank is different
Application(bank=3, mortgage=2, status='active')
换句话说,我不能创建一个具有相同银行、相同抵押贷款和状态的应用程序
draft
如果已经有一个具有相同银行和抵押贷款的申请,并且状态不是
草稿
。
有可能做这样的约束吗?将
CheckConstraint
工作