[Answered ]-Django access m2m field attribute from a queryset

2👍

Found solution, added rooms in the prefetch_related,

res = Reservation.objects.filter(hotel=hotel).prefetch_related('rooms')

and then in the template,

{% for room in res.rooms.all() %}
   <td>{{ room.number }}</td>
{% endfor %}

and its now showing the desired result i.e the room numbers!

Leave a comment