Skip to content

Instantly share code, notes, and snippets.

@DamianMullins
Created August 13, 2012 19:50
Show Gist options
  • Save DamianMullins/3343596 to your computer and use it in GitHub Desktop.
Save DamianMullins/3343596 to your computer and use it in GitHub Desktop.
Check that submitted URL is unique and allowed
def clean_url(self):
INVALID_URLS = ('about', 'admin', 'register')
url = self.cleaned_data['url']
try:
post = Post.objects.get(url=url)
except Post.DoesNotExist:
pass
else:
raise forms.ValidationError(u'%s already exists' % post )
if url in INVALID_URLS:
raise forms.ValidationError(u'%s is not a valid url' % url )
return url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment