mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-13 13:12:42 +00:00
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:
@ -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):
|
||||
|
Reference in New Issue
Block a user