如何获取模型TrustyRequest
字段status
的先前数据。由于这种情况,我需要status field
的先前数据
if User.objects.filter(email=email).exists() and status=='Accepted':
我想查看status
字段的先前状态,并与正在更新的当前状态-status=='Accepted'
进行比较。
class TrustyRequestForm(forms.ModelForm):
class Meta:
model = TrustyRequest
fields = [
'masjid_name',
'masjid_address',
'first_name',
'last_name',
'email',
'phone_number',
'status',
]
def clean(self):
cleaned_data = super().clean()
email = cleaned_data.get("email")
status = cleaned_data.get("status")
if User.objects.filter(email=email).exists() and status=='Accepted':
raise forms.ValidationError("Email Already Exists")
答案 0 :(得分:0)
要获取以前的实例,请使用self.instance.status