1
0
Fork 0

Add dynamic item select loading

This commit is contained in:
Piotr Dobrowolski 2017-10-08 18:01:03 +02:00
parent 760f074f49
commit 60f60bd1f5
2 changed files with 15 additions and 2 deletions

4
static/css/admin.css Normal file
View File

@ -0,0 +1,4 @@
/* django-admin CSS patches */
.select2-container {
min-width: 400px;
}

View File

@ -1,9 +1,15 @@
from django import forms from django import forms
from django.contrib import admin from django.contrib import admin
from .models import Item, ItemImage, Category, Label from .models import Item, ItemImage, Category, Label
from django_select2.forms import Select2Widget, Select2MultipleWidget from django_select2.forms import ModelSelect2Widget, Select2MultipleWidget
class ItemSelectWidget(ModelSelect2Widget):
search_fields = [
'name__icontains',
'description__icontains'
]
class ItemForm(forms.ModelForm): class ItemForm(forms.ModelForm):
name = forms.CharField(widget=forms.TextInput()) name = forms.CharField(widget=forms.TextInput())
@ -11,7 +17,7 @@ class ItemForm(forms.ModelForm):
model = Item model = Item
exclude = [] exclude = []
widgets = { widgets = {
'parent': Select2Widget, 'parent': ItemSelectWidget,
'categories': Select2MultipleWidget 'categories': Select2MultipleWidget
} }
@ -54,6 +60,9 @@ class ItemAdmin(admin.ModelAdmin):
# Required by select2 # Required by select2
'https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
) )
css = {
'all': ('css/admin.css',)
}
def response_action(self, request, queryset): def response_action(self, request, queryset):
with Item.disabled_tree_trigger(): with Item.disabled_tree_trigger():