Multipleobjectsreturned

Asked

Viewed 68 times

0

When I create two topics with the same name, error:Multipleobjectsreturned

class ForumView(ListView):
    paginate_by = 5
    template_name = 'forum/forum.html'
    def get_queryset(self):
        queryset = Thread.objects.filter()
        order = self.request.GET.get('order','')
        if order == 'views':
            queryset = queryset.order_by('-views')
        elif order == 'answers':
            queryset = queryset.order_by('-answers')
        return queryset

How to change the query to avoid error with thread of the same name?

  • 1

    What is the stack trace of the exception?

  • Try replacing Filter() with all() or pass some argument to filter()

  • In which line does the error occur? Posting stackTrace would help a lot, as @Ivella suggested

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.