I have a custom validator for a field in a model Postthat will be used in the admin interface authentication goal is to verify that no other e-mail does not have the same url, and category, but I can not find a way to distinguish from the renovation or newPost ; which in the case of an update will not be a problem with the existence of Postthe same URL and category.
Here is the validator:
class MyPostAdminForm(forms.ModelForm):
class Meta:
model = Post
def clean_url(self):
url = self.cleaned_data['url']
try:
cat = self.cleaned_data['category']
except KeyError:
return url
if UPDATE:
return url
else:
try:
Post.objects.get(category=cat, url=url)
except Post.DoesNotExist:
return url
else:
raise forms.ValidationError('Already exists post with category "%s" and url "%s"'%(cat, url))
Any ideas?
source
share