I want to do a chained filtering but it does not work
def queryset(self, request):
qs = super(MaterialAdmin, self).queryset(request)
if request.user.is_superuser:
self.exclude = []
return qs
else:
self.exclude = ['droits_acces', 'groupe']
ff = qs.filter(groupe= request.user)
gg = qs.filter(user=request.user)
jj = qs.filter(user=request.user).filter(groupe= request.user)
return jj
How to do ?
ff = [CC409, ST54]
gg = [Al2O3, BB79, CC409]
I would like to have
jj = [CC409, ST54, Al2O3, BB79]
You can use the Q object for complex queries.
from django.db.models import Q
...
def queryset(self, request):
...
return qs.filter(Q(groupe=request.user)|Q(user=request.user))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.