-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathlookups.py
38 lines (31 loc) · 1.57 KB
/
lookups.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# coding:utf-8
"""
Ajax custom lookup
@author: Sébastien Renard <Sebastien.Renard@digitalfox.org>
@license: AGPL v3 or newer (http://www.gnu.org/licenses/agpl-3.0.html)
"""
from staffing.models import Mission
from django.db.models import Q
class MissionLookup(object):
def get_query(self, q, request):
""" return a query set. you also have access to request.user if needed """
qs = Mission.objects.filter(active=True) # Remove archived mission
# Get mission with lead by lead and client name
qs = qs.filter(Q(deal_id__icontains=q) |
Q(description__icontains=q) |
Q(lead__name__icontains=q) |
Q(lead__deal_id__icontains=q) |
Q(lead__client__organisation__name__icontains=q) |
Q(lead__client__organisation__company__name__icontains=q))
return qs
def format_result(self, mission):
""" the search results display in the dropdown menu. may contain html and multiple-lines. will remove any | """
return mission.full_name()
def format_item(self, mission):
""" the display of a currently selected object in the area below the search box. html is OK """
return str(mission)
def get_objects(self, ids):
""" given a list of ids, return the objects ordered as you would like them on the admin page.
this is for displaying the currently selected items (in the case of a ManyToMany field)
"""
return Mission.objects.filter(pk__in=ids).order_by('lead', 'description')