forked from DGNum/gestioCOF
Upgrade to Django 1.11
- Deprecation warnings using Django 1.8 are resolved. - Deprecation warnings using Django 1.11 are resolved. - Admin: grappelli is no longer used. - Upgrade to django-autocomplete-light v3 (v2 is not 1.11 compatible). * autocomplete.modelform_factory being dropped, code uses dal Select2 views and widgets.
This commit is contained in:
parent
36ce038050
commit
b0b0542407
44 changed files with 341 additions and 278 deletions
26
utils/views/autocomplete.py
Normal file
26
utils/views/autocomplete.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from django.db.models import Q
|
||||
|
||||
from dal import autocomplete
|
||||
|
||||
|
||||
class Select2QuerySetView(autocomplete.Select2QuerySetView):
|
||||
model = None
|
||||
search_fields = []
|
||||
|
||||
def get_queryset_filter(self):
|
||||
q = self.q
|
||||
filter_q = Q()
|
||||
|
||||
if not q:
|
||||
return filter_q
|
||||
|
||||
words = q.split()
|
||||
|
||||
for word in words:
|
||||
for field in self.search_fields:
|
||||
filter_q |= Q(**{'{}__icontains'.format(field): word})
|
||||
|
||||
return filter_q
|
||||
|
||||
def get_queryset(self):
|
||||
return self.model.objects.filter(self.get_queryset_filter())
|
Loading…
Add table
Add a link
Reference in a new issue