madhu131313
madhu131313

Reputation: 7386

Filtering using queryset in django with the attribute in a given set

qs  = super(UserAdmin, self).queryset(request)
current_user = User.objects.get(username=request.user)
followers = UserProfile.objects.filter(lead_user=current_user)
return qs.filter(????)

qs is my queryset and

I want to literally return this

qs.filter(if lead_user is in followers ,add this else exclude )

Upvotes: 0

Views: 28

Answers (1)

karthikr
karthikr

Reputation: 99620

You could use __in

qs = qs.filter(user__in=followers)

Basically, filter only the UserAdmin objects that are in followers

(replace user__ with the appropriate field)

Upvotes: 1

Related Questions