Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
The most correct way is to redefine the form and check the necessary condition in it:
class SomeForm(forms.ModelForm):
class Meta:
model = SomeModel
fields = ['some_field', 'another_field', 'one_more_field']
def clean(self):
if проверка условия:
raise forms.ValidationError('Существует инстанс модели с некоторыми параметрами!')
class SomeInline(admin.TabularInline):
model = Book
form = SomeForm
class AnotherModel(admin.ModelAdmin):
...
def save_formset(self, request, form, formset, change):
instances = formset.save(commit=False)
for instance in instances:
if проверка условия:
raise forms.ValidationError('Существует инстанс модели с некоторыми параметрами!')
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question