Django: want to sort comments by datetime

Viewed 16813

I have in my view comments and I want to sort them with the latest comment at the top of the list. However it is not working. I get this error.

Caught TypeError while rendering: 'Comment' object is not iterable

I am not so sure what is causing this problem. Here is my views and model which may help.

Views

def home(request):
    comments = Comment.objects.latest('datetime')
    return render_to_response('home.html', {'comments':comments}, context_instance=RequestContext(request))

models

class Comment(models.Model):
    name = models.CharField(max_length = 40)
    datetime = models.DateTimeField(default=datetime.now)
    note = models.TextField()
    def __unicode__(self):
        return unicode(self.name)
3 Answers
Related