Mercurial > public > sg101
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/weblinks/forms.py Sat May 05 17:10:48 2012 -0500 @@ -0,0 +1,23 @@ +""" +Forms for the weblinks application. +""" + +from django import forms +from weblinks.models import PendingLink, Link + + +class AddLinkForm(forms.ModelForm): + title = forms.CharField(widget = forms.TextInput(attrs = {'size': 52})) + url = forms.CharField(widget = forms.TextInput(attrs = {'size': 52})) + + def clean_url(self): + new_url = self.cleaned_data['url'] + try: + Link.objects.get(url__iexact = new_url) + except Link.DoesNotExist: + return new_url + raise forms.ValidationError('That link already exists in our database.') + + class Meta: + model = PendingLink + exclude = ('user', 'date_added', 'update_date')