[Answer]-Select_related or select_prefetched after calling filter()?

1👍

Yes you can
As you can see:

type(MyModel.objects.filter(pk=1))
<class 'django.db.models.query.QuerySet'>

type(MyModel.objects.filter(pk=1).select_related())
<class 'django.db.models.query.QuerySet'>

type(MyModel.objects.filter(pk=1).select_related().filter(name='test'))
<class 'django.db.models.query.QuerySet'>

All of them are QuerySets

0👍

I just tested it in the shell:

>>> from myApp.models import Unit_type, Transaction
>>> u = Unit_type.objects.get(pk=1)
>>> t = Transaction.objects.filter(unit_type=u)
>>> t = t.select_related().filter(transaction_end_status='R')

It didn’t give me an error and gave me a queryset with length 1.

Leave a comment