Commit 7834a018 authored by David Haynes's avatar David Haynes 🙆
Browse files

Short urls now accept numbers,hypens, etc. (Closes #9)

- now a slugfield
- removed alphanumeric check since that would defeat the purpose
parent 14a6fe41
...@@ -28,12 +28,6 @@ class URLForm(forms.ModelForm): ...@@ -28,12 +28,6 @@ class URLForm(forms.ModelForm):
widget=forms.RadioSelect(), widget=forms.RadioSelect(),
) )
# Short field must be only letters.
alphanumeric = RegexValidator(
r'^[a-zA-Z]*$',
'Only letters are allowed.'
)
def unique_short(value): def unique_short(value):
try: try:
URL.objects.get(short__iexact=value) URL.objects.get(short__iexact=value)
...@@ -42,11 +36,11 @@ class URLForm(forms.ModelForm): ...@@ -42,11 +36,11 @@ class URLForm(forms.ModelForm):
raise ValidationError('Short url already exists.') raise ValidationError('Short url already exists.')
# Custom short-url field with validators. # Custom short-url field with validators.
short = forms.CharField( short = forms.SlugField(
required=False, required=False,
label='Short URL (Optional)', label='Short URL (Optional)',
widget=forms.TextInput(attrs={}), widget=forms.TextInput(attrs={}),
validators=[alphanumeric, unique_short], validators=[unique_short],
max_length=20, max_length=20,
min_length=3, 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