I have a simple filter where a user enters a string, term
, which is compared against the column companyId
in my local database. If there is a match, the appropriate record/s are then rendered in a table within my template. However, no data is being rendered in the template, only rows of empty fields matching the number of records for a particular query. I have similar logic used for displaying these records unfiltered which works fine.
Edit:
When I removed the key value and tried to render only the object such as {{ object }}
, the following is displayed: (Opportunity: Opportunity object (8)
views.py
def opportunity_dashboard(request):
try:
term = request.GET.get('search_query')
if term:
filtered_objects = Opportunity.objects.filter(companyId__icontains=term)
filtered_local_zip = zip(filtered_objects)
context = {
'term': term,
'filtered_local_zip': filtered_local_zip,
'filtered_connectwise_zip': filtered_connectwise_zip
}
return render(request, 'website/opportunity_dashboard.html', context)
template.html
{% if term %}
{% for object in filtered_local_zip %}
<tr>
<th style="text-align: center;">
<a href="https://solutions.byteworks.com/new_opportunity/new_opportunity_review?id={{ object.id }}">✎</a>
</th>
<td>
<div class="select">
<select disabled id="bw_status" name="status">
<option value="{{ object.status }}">{{ object.status }}</option>
</select>
</div>
</td>
<td>
<a{{ object.opportunityName }}</a>
</td>
<td>{{ object.companyId }}</td>
<td>
<div class="select">
<select id="bw_account_manager" name="account_manager">
<option value="{{ object.accountManager }}">{{ object.accountManager }}</option>
</select>
</div>
</td>