0

I want to use django_filter, but my datatype is list. it shows that list has no attribute model

myfiler1 = Orderfilter(request.GET, queryset=mylist) 

I want to use django_filter, but my datatype is list. it shows that list has no attribute model

myfiler1 = Orderfilter(request.GET, queryset=mylist) 

so how to convert my list to django.db.models.query.QuerySet

18
  • Take a look at stackoverflow.com/questions/18607698/… and see if helps. Commented Jun 27, 2023 at 6:51
  • You should pass your queryset instead of converting it to a list. The list type and QuerySet are two types. Commented Jun 27, 2023 at 7:01
  • 1
    The best solution is to avoid making a list in the first place. Try real hard to achieve whatever logic you have through the ORM and resist the urge to filter in the more familiar Python. If that is not possible, you can always do the brutish sq = MyModel.objects.filter(pk__in=[m.pk for m in mylist]) to convert it back to a queryset. Commented Jun 27, 2023 at 7:13
  • I have saw this above their data is queryset but my original data type is a list. so is there anyway to convert list to queryset? Commented Jun 27, 2023 at 7:23
  • queryset is so difficult to merge or sum by columns, particular hard for dirty data Commented Jun 27, 2023 at 7:29

1 Answer 1

0

You need to pass orderdata = myfiler1.qs

orderdata = OrdersModel.objects.filter(user=request.user)
myfiler1 = Orderfilter(request.GET, queryset=orderdata) 
orderdata = myfiler1.qs
Sign up to request clarification or add additional context in comments.

6 Comments

true, but my orderdata is a list
you need must be pass queryset in filter not list
yes I know, so how to convert my list to queryset
plz update question with full code
I mean I want to see mylist
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.