Commit 74f51dea authored by Jean Michel Rouly's avatar Jean Michel Rouly
Browse files

Validate forms for previously existing shorts.

parent a7c97649
from django import forms
from go.models import URL
from django.core.validators import MinLengthValidator, MinValueValidator, RegexValidator
from django.core.exceptions import ValidationError
class URLForm( forms.ModelForm ):
......@@ -31,12 +32,19 @@ class URLForm( forms.ModelForm ):
'Only letters are allowed.'
def unique_short( value ):
except URL.DoesNotExist:
raise ValidationError('Short url already exists.')
# Custom short-url field with validators.
short = forms.CharField(
required = False,
label = 'Short URL (Optional)',
widget = forms.TextInput(attrs={}),
validators = [alphanumeric],
validators = [alphanumeric,unique_short],
max_length = 20,
min_length = 3,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment