我在我的管理页面中使用表格内联,其中一条指令可能有多个废弃代码和事件代码。但是一个代码或事件代码不能有多条指令。 我在整个表中创建了报废代码和事件代码,这样它们就不能被复制了
我的管理员
class InstructionAdmin(admin.ModelAdmin):
inlines = [ ScrapEventInstructionMapInline, ]
fields=('name',)
form = InstructionMapForm
当用户试图输入已经存在的事件代码或废弃代码时,我需要向他们显示一个警报。 但问题是,即使我们有数据指令,s\u码和e\u码都是无的
我的表格.pyfile:- 你知道吗
class InstructionMapForm(forms.ModelForm):
def clean(self):
instruction = self.cleaned_data.get('instruction')
s_code = self.cleaned_data.get('scrap_code')
e_code = self.cleaned_data.get('event_code')
qs = ScrapEventInstructionMap.objects.all()
if s_code:
dup_scrap = list(ScrapEventInstructionMap.objects.filter(scrap_code=s_code).values('scrap_code'))
if dup_scrap:
raise forms.ValidationError ('The Scrap Code provided ({}) already exists, kindly edit it or provide another Scrap Code'.format(s_code))
elif e_code:
dup_event = list(ScrapEventInstructionMap.objects.filter(event_code=e_code).values('event_code'))
if dup_event:
raise forms.ValidationError ('The Event Code provided ({}) already exists, kindly edit it or provide another Event Code'.format(e_code))
如何避免无数据获取?如何向用户显示警报
类说明dminformset(forms.models.BaseInlineFormSet):
相关问题 更多 >
编程相关推荐