Answer the question
In order to leave comments, you need to log in
How to check Django field uniqueness and show on form?
How to display an error on the form, such a record already exists?
did so
class OidForm(forms.Form):
oidDescription = forms.CharField(max_length=100)
oidSlug = forms.CharField(max_length=50)
oid = forms.CharField(max_length=100)
oidDescription.widget.attrs.update({'class': 'form-control'})
oidSlug.widget.attrs.update({'class': 'form-control'})
oid.widget.attrs.update({'class': 'form-control'})
def clean_oid(self):
data = self.cleaned_data['oid']
# print(self.cleaned_data)
if Oid.objects.filter(oid=data).exists():
raise ValidationError('Already exists')
return self
Don't mix *args and **kwargs in call to reverse()!
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question