when I try to add pagination to my page it gives me error object of type 'RawQuerySet' has no len()
views:
class StudentmessageListView(ListView, LoginRequiredMixin):
login_url = '/login/'
redirect_field_name = 'redirect_to'
template_name = 'student_messagesall.html'
context_object_name = 'messages_all'
model = Message
paginate_by = 3
def get_queryset(self):
return Message.objects.raw('SELECT * FROM ertaapp_message where to_prof_id=%s ORDER BY create_date DESC',[self.request.user.id])
def get_context_data(self, **kwargs):
context = super(StudentmessageListView, self).get_context_data(**kwargs)
context['reps'] = ReplyMessage.objects.raw('SELECT * FROM ertaapp_replymessage')
return context
how can I solve this?
Both the question and the answer are no longer relevant since Django 2.1 introduced the len() method of RawQuerySet.
You should return the list instead of raw queryset.
def get_queryset(self):
return list(Message.objects.raw('SELECT * FROM ertaapp_message where to_prof_id=%s ORDER BY create_date DESC',[self.request.user.id]))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With