[Answer]-Grabbing field from a query set in Django

1👍

filter operation always returns list so you can display it using loop:

{% for l in listname %}
    {{ l }}
{% endfor %}

or you can just call method first if you are sure that it always exists and only one:

listname = request.user.newlist_set.filter(list_name__iexact=listname).first()

If there is no listname then it’s None. You can check this in template:

{% if listname %}
     {{ listname }}
{% else %}
     No list with this name.
{% endif %}
👤bellum

Leave a comment