mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Admin now uses a custom form to sort User selection box
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from django.contrib import admin
|
||||
from reddit.models import RedditAccount
|
||||
from reddit.forms import RedditAccountForm
|
||||
|
||||
class RedditAccountAdmin(admin.ModelAdmin):
|
||||
list_display = ('username', 'user', 'date_created', 'link_karma', 'comment_karma', 'last_update')
|
||||
@@ -7,6 +8,8 @@ class RedditAccountAdmin(admin.ModelAdmin):
|
||||
|
||||
fields = ('user', 'username')
|
||||
|
||||
form = RedditAccountForm
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
obj.api_update()
|
||||
obj.save()
|
||||
|
||||
16
reddit/forms.py
Normal file
16
reddit/forms.py
Normal 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")
|
||||
Reference in New Issue
Block a user