Reputation: 221
I'm doing a django app which consists in an e-commerce website.
I have a profile page, and inside I show all articles bought by the connected user. So for that I do a QuerySet:
class ProfileView(generic.ListView):
template_name = 'eduardoApp/profile.html'
context_object_name = 'order_list'
def get_queryset(self):
return Order.objects.filter(user=self.request.user.id,ordered=True)
And in my profile page I do like this:
{% for order in order_list %}
<div>
<p> {{ order.user }} </p>
<p> {{ order.articles.all}} </p>
<pl> {{ order.ordered }} </p>
<p> {{ order.ordered_date }} </p>
</div>
{% endfor %}
The
order.articles.all is returning the following : <QuerySet [<OrderArticle: Bottle of Wine>]>
But my question is : how do I only display 'Bottle of Wine' ? Instead of diplaying QuerySet {<....>
Upvotes: 0
Views: 30
Reputation: 15738
You have to iterate through articles
{% for order in order_list %}
<div>
<p> {{ order.user }} </p>
{% for article in order.articles.all %}
<p> {{ article.name }} </p>
{% endfor %}
<pl> {{ order.ordered }} </p>
<p> {{ order.ordered_date }} </p>
</div>
{% endfor %}
Upvotes: 2