regluit/libraryauth/admin.py

55 lines
1.6 KiB
Python
Raw Normal View History

2018-07-26 17:59:58 +00:00
from django import forms
from django.contrib.admin import ModelAdmin, site
from django.contrib.auth.models import User
from selectable.base import ModelLookup
2018-07-26 17:59:58 +00:00
from selectable.forms import AutoCompleteSelectWidget, AutoCompleteSelectField
from selectable.registry import registry
2018-07-26 17:59:58 +00:00
from . import models
class UserLookup(ModelLookup):
model = User
search_fields = ('username__icontains',)
registry.register(UserLookup)
class LibraryAdminForm(forms.ModelForm):
user = AutoCompleteSelectField(
2018-07-26 17:59:58 +00:00
UserLookup,
widget=AutoCompleteSelectWidget(UserLookup),
required=True,
)
2013-11-30 20:41:05 +00:00
owner = AutoCompleteSelectField(
2018-07-26 17:59:58 +00:00
UserLookup,
widget=AutoCompleteSelectWidget(UserLookup),
required=True,
)
class Meta(object):
model = models.Library
2018-07-26 17:59:58 +00:00
widgets = {'group':forms.HiddenInput}
exclude = ('group', )
2018-07-26 17:59:58 +00:00
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)
2018-07-26 17:59:58 +00:00
site.register(models.EmailPattern, EmailPatternAdmin)