I’m using a raw query and i’m having trouble finding out how to get the number of results it returns. Is there a way?
edit
.count() doesnt work. it returns: ‘RawQuerySet’ object has no attribute ‘count’
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I presume you’re talking about theraw()queryset method. That returns a queryset just like any other. So of course you can call.count()on it, just like you would on any other ORM query.Edit Shows what happens when you don’t check. As you note,
.raw()returns a RawQuerySet which doesn’t have a count method – and neither does it supportlen(). The only way to get the length is to iterate through the queryset and count them: