regluit/libraryauth/admin.py

54 lines
1.6 KiB
Python
Raw Normal View History

from . import models
from selectable.forms import AutoCompleteSelectWidget,AutoCompleteSelectField
from selectable.base import ModelLookup
from selectable.registry import registry
from django import forms
from django.contrib.admin import ModelAdmin, site
from django.contrib.auth.models import User, Group
class UserLookup(ModelLookup):
model = User
search_fields = ('username__icontains',)
registry.register(UserLookup)
class LibraryAdminForm(forms.ModelForm):
user = AutoCompleteSelectField(
UserLookup,
widget=AutoCompleteSelectWidget(UserLookup),
required=True,
)
2013-11-30 20:41:05 +00:00
owner = AutoCompleteSelectField(
UserLookup,
widget=AutoCompleteSelectWidget(UserLookup),
required=True,
)
class Meta(object):
model = models.Library
widgets= {'group':forms.HiddenInput}
exclude = ('group', )
class LibraryAdmin(ModelAdmin):
list_display = ('user', )
form = LibraryAdminForm
search_fields = ['user__username']
class BlockAdmin(ModelAdmin):
list_display = ('library', 'lower', 'upper',)
2013-11-30 20:41:05 +00:00
search_fields = ('library__name', 'lower', 'upper',)
class CardPatternAdmin(ModelAdmin):
list_display = ('library', 'pattern', 'checksum',)
2013-11-30 20:41:05 +00:00
search_fields = ('library__name', )
2013-10-11 02:31:31 +00:00
class EmailPatternAdmin(ModelAdmin):
list_display = ('library', 'pattern', )
2013-11-30 20:41:05 +00:00
search_fields = ('library__name',)
site.register(models.Library, LibraryAdmin)
site.register(models.Block, BlockAdmin)
site.register(models.CardPattern, CardPatternAdmin)
site.register(models.EmailPattern, EmailPatternAdmin)