From 60f60bd1f574bb0d68f1f4f9e32e7370b9907cee Mon Sep 17 00:00:00 2001 From: Piotr Dobrowolski Date: Sun, 8 Oct 2017 18:01:03 +0200 Subject: [PATCH] Add dynamic item select loading --- static/css/admin.css | 4 ++++ storage/admin.py | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 static/css/admin.css diff --git a/static/css/admin.css b/static/css/admin.css new file mode 100644 index 0000000..3fdc438 --- /dev/null +++ b/static/css/admin.css @@ -0,0 +1,4 @@ +/* django-admin CSS patches */ +.select2-container { + min-width: 400px; +} diff --git a/storage/admin.py b/storage/admin.py index 5085253..034bb1c 100644 --- a/storage/admin.py +++ b/storage/admin.py @@ -1,9 +1,15 @@ from django import forms from django.contrib import admin 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): name = forms.CharField(widget=forms.TextInput()) @@ -11,7 +17,7 @@ class ItemForm(forms.ModelForm): model = Item exclude = [] widgets = { - 'parent': Select2Widget, + 'parent': ItemSelectWidget, 'categories': Select2MultipleWidget } @@ -54,6 +60,9 @@ class ItemAdmin(admin.ModelAdmin): # Required by select2 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', ) + css = { + 'all': ('css/admin.css',) + } def response_action(self, request, queryset): with Item.disabled_tree_trigger():