I have the following model:
class Credit(models.Model):
user = models.ForeignKey(User)
...
and a ListView
class CreditListView(ListView):
paginate_by = 10
model = Credit
...
if I want to filter the credits by users in side CreditListView:
def get_queryset(self):
users = User.objects.filter(...)[:10]
credits = Credits.objects.filter(user__in=users)
return credits
I will get a NotSupportedError exception:
(1235, "This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'")
Try this :
users = User.objects.filter(...)[:10]
users = list(users)
credits = Credits.objects.filter(user__in=users)
Django model returns a list which exactly isn't a Python list but an extended form of that. But that has some limitations. Hence, we need to convert that into a Python understandable list.
The problem was this line:
users = User.objects.filter(...)[:10]
It doesn't like the limit within the subquery, I thought I have tried removing it, could be django server didn't restart properly.
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