Commit b9510c78 authored by David Haynes's avatar David Haynes 🙆
Browse files

Merge branch 'issue9' into 'master'

Modify short url to be a slugfield

change other things accordingly, see commit messages

See merge request !15
parents f27ed720 7834a018
......@@ -28,12 +28,6 @@ class URLForm(forms.ModelForm):
widget=forms.RadioSelect(),
)
# Short field must be only letters.
alphanumeric = RegexValidator(
r'^[a-zA-Z]*$',
'Only letters are allowed.'
)
def unique_short(value):
try:
URL.objects.get(short__iexact=value)
......@@ -42,11 +36,11 @@ class URLForm(forms.ModelForm):
raise ValidationError('Short url already exists.')
# Custom short-url field with validators.
short = forms.CharField(
short = forms.SlugField(
required=False,
label='Short URL (Optional)',
widget=forms.TextInput(attrs={}),
validators=[alphanumeric, unique_short],
validators=[unique_short],
max_length=20,
min_length=3,
)
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('go', '0002_auto_20140911_1336'),
]
operations = [
migrations.AlterField(
model_name='url',
name='short',
field=models.SlugField(max_length=20, serialize=False, primary_key=True),
),
]
......@@ -21,7 +21,7 @@ class URL(models.Model):
date_created = models.DateTimeField(default=timezone.now)
target = models.URLField(max_length=1000)
short = models.CharField(primary_key=True, max_length=20)
short = models.SlugField(primary_key=True, max_length=20)
clicks = models.IntegerField(default=0)
qrclicks = models.IntegerField(default=0)
......
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