I have the following in a view (foreign key relationships via _set):
srvr = Server.objects.get(name=q)
return render_to_response('search_results.html',
{'drv': srvr.drive_set.all(), 'memry': srvr.memory_set.all(), 'query': q})
The results template includes:
{% if drv %}
<table>
<tr>
<td>{{ drv }}</td>
</tr>
</table>
{% endif %}
{% if memry %}
<li>{{ memry }}</li>
{% endif %}
The output looks like this:
[<Drive: IBM IBM-500 1111111 500Gb SATA>, <Drive: IBM IBM-500 2222222 500Gb SATA]
[<Memory: Samsung 512>, <Memory: Samsung 512>, <Memory: Samsung 512>]
I know this the result of the “unicode()” method in the “Drive” and “Memory” classes.
How can I control the output/formatting so that the brackets and class name don’t appear, and only specific fields. ?
drvandmemryare going to be iterable, and you can move through them with thefortag…The
.nameand.sizeare properties of whatever Modeldrepresents. Fill this in with whatever details actually exist that you’re looking to render.