I have Shop model class. I am passing a QueryString to raw Django ORM to get all non duplicate records + 1 record from duplicates.
Below is the query:
qs = Shop.objects.raw(select a.* from customers a INNER JOIN (SELECT city ,MIN(id) as id FROM customers GROUP BY city) AS b ON a.city = b.city AND a.id = b.id)
Here I get a Raw Query Set.I want to know the count of queried result. How I can proceed?
For Pagination:
page_object = Pagination(qs, 2)
page_count = page_object.num_pages
After executing above line i am getting an error as:
TypeError: object of type 'RawQuerySet' has no len()
Can someone have any idea?How can i apply pagination to my raw queryset.
Whatever things i am trying is because i am using MySQL as DB.
"pagination = Paginator(qs, records_per_page)
totalPageCount = pagination._count = len(list(qs))"
I got the error on 2nd line as You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BY created' at line 1
One thing i just want to make sure is it possible to count the records from a raw QuerySet If so then how?