comparison weblinks/forms.py @ 581:ee87ea74d46b

For Django 1.4, rearranged project structure for new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 May 2012 17:10:48 -0500
parents gpp/weblinks/forms.py@d424b8bae71d
children 176d1550bf25
comparison
equal deleted inserted replaced
580:c525f3e0b5d0 581:ee87ea74d46b
1 """
2 Forms for the weblinks application.
3 """
4
5 from django import forms
6 from weblinks.models import PendingLink, Link
7
8
9 class AddLinkForm(forms.ModelForm):
10 title = forms.CharField(widget = forms.TextInput(attrs = {'size': 52}))
11 url = forms.CharField(widget = forms.TextInput(attrs = {'size': 52}))
12
13 def clean_url(self):
14 new_url = self.cleaned_data['url']
15 try:
16 Link.objects.get(url__iexact = new_url)
17 except Link.DoesNotExist:
18 return new_url
19 raise forms.ValidationError('That link already exists in our database.')
20
21 class Meta:
22 model = PendingLink
23 exclude = ('user', 'date_added', 'update_date')