2
values()
returns a special class named ValuesQuerySet
which acts like a list of dictionaries containing the properties you pass into that as key/value pairs.
Given the above information, the following query will give you a list of dictionaries where each of them contains a FileField
instance for each ClientUploads object:
files = ClientUploads.objects.filter(client=current_client).values('file_upload')
It may not be easy to iterate over a list of dicts in the template so I would change the above query as follows:
files = ClientUploads.objects.filter(client=current_client)
and update for loop in the template like this:
{% for file in files %}
{% with uploaded_file=file.file_upload %}
<tr>
<th>{{ uploaded_file.name }}</th>
<th>{{ uploaded_file.size }}</th>
<th>{{ uploaded_file.url }}</th>
</tr>
{% endwith %}
{% endfor %}
Hope this helps.
Source:stackexchange.com