2

I am having an odd problem... This code was working fine until I worked on some of the other views, and now, it isn't working.

Here is my view:

def showTickets(request, project_slug): project = Project.objects.get(slug=project_slug) tickets = Ticket.objects.get(project=project) payload = { 'project':project, 'tickets':tickets} return render(request, 'project/tickets.html', payload) 

Template:

{% extends 'project/base.html' %} {% block title %}Tickets: {{project.name}}{% endblock %} {% block main %} <div id="project-nav"> <span><a href="/project/{{project.slug}}/">Tickets</a></span> <span><a href="/book/{{book.slug}}{{book.name}}">Docs</a></span> <span><a href="/project/{{project.slug}}/browse">Browser</a></span> </div> <div id="action-nav"> {% block actions %} <span><a href="/project/{{project.slug}}/tickets/create">Create Ticket</a></span> <span><a href="/project/{{ project.slug }}/tickets/recent/">Recent Activity</a></span> <span><a href="/project/{{ project.slug }}/tickets/my/">My Tickets</a></span> {% endblock %} </div> {% for ticket in tickets %} <div class="ticket"> <div class="ticket-header"> <div class="ticket-title"> <a href="/project/ticket/{{ticket.pk}}">{{ticket.subject}}</a> </div> <div id="ticket-number"> #{{ticket.pk}} </div> <div id="ticket-state"> {{ticket.get_state_display}} </div> <div id="ticket-info"> Reported by {{ticket.created_by}} | created: {{ticket.created_on }} | modified: {{ticket.modified_on}} </div> </div> </div> {% endfor %} </div> {% endblock %} 

Error:

Template error: In template c:........\project\tickets.html, error at line 19 Caught TypeError while rendering: 'Ticket' object is not iterable 

This was working fine until I worked on some other views...not sure why it isn't working now? If any one can help I'd appreciate it!

2 Answers 2

7
project = Project.objects.get(slug=project_slug) tickets = Ticket.objects.get(project=project) 

These two lines are the cause of your troubles. They aren't returning an iterable, such as a list, but an object, which isn't iterable at all. Instead of a get, use a filter instead, which will return a list.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Worked like a charm! I think i'd just been looking at it too long. :)
3

The get() method returns a single object. Perhaps you meant to use the filter() method instead?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.