Admin now uses a custom form to sort User selection box

This commit is contained in:
2010-03-03 15:03:48 +00:00
parent 2f3ea3f48b
commit 91bd276ace
2 changed files with 19 additions and 0 deletions

16
reddit/forms.py Normal file
View File

@@ -0,0 +1,16 @@
from django import forms
from django.contrib.auth.models import User
from reddit.models import RedditAccount
class RedditAccountForm(forms.ModelForm):
user = forms.ModelChoiceField(queryset=User.objects.order_by('username'))
username = forms.CharField(label = u'Reddit Username', max_length=64)
def clean(self):
try:
eaccount = RedditAccount.objects.get(username=self.cleaned_data['username'])
except RedditAccount.DoesNotExist:
return self.cleaned_data
else:
raise forms.ValidationError("This User ID is already registered")