Implement auto-complete for /admin/ forms that reference User

We have so many users now that loading these forms take forever.
Instead, implement a textbox with autocomplete using django-selectable,
which will not load the whole list of users at once.
This commit is contained in:
Magnus Hagander
2016-06-23 17:57:38 +02:00
parent a6d3b44038
commit 27e1c73368
6 changed files with 86 additions and 2 deletions

View File

@ -1,14 +1,33 @@
from django import forms
from django.contrib import admin
from selectable.forms.widgets import AutoCompleteSelectMultipleWidget
from pgweb.core.models import Version, OrganisationType, Organisation
from pgweb.core.models import ImportedRSSFeed, ImportedRSSItem
from pgweb.core.models import ModerationNotification
from pgweb.core.lookups import UserLookup
class OrganisationAdminForm(forms.ModelForm):
class Meta:
model = Organisation
exclude = ()
widgets = {
'managers': AutoCompleteSelectMultipleWidget(lookup_class=UserLookup),
}
def __init__(self, *args, **kwargs):
super(OrganisationAdminForm, self).__init__(*args, **kwargs)
self.fields['managers'].widget.can_add_related = False
self.fields['managers'].widget.can_change_related = False
self.fields['managers'].widget.can_delete_related = False
class OrganisationAdmin(admin.ModelAdmin):
form = OrganisationAdminForm
list_display = ('name', 'approved', 'lastconfirmed',)
list_filter = ('approved',)
ordering = ('name', )
filter_horizontal = ('managers', )
search_fields = ('name', )
class VersionAdmin(admin.ModelAdmin):