def ajax_list_loader request condition dict if request method POST sea

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
def ajax_list_loader(request):
condition = dict()
if request.method == 'POST':
search = request.POST.get('search', None)
if search is not None:
if re.search('^[0-9]+$', search):
condition['dealings__dealing_number__startswith'] = search
else:
condition['company_full_name__icontains'] = search
companies = Companies.objects.select_related().filter(dealings__manager_id=request.user_id, **dict(condition))
return {'companies': companies}
############# TEMPLATE
{% for company in companies %}
{{ company.name }}
{% for deal in company.dealings_set.all %}
{{ deal.deal_num }}
{% endfor %}
{% endfor %}