Django query to filter out current user from a list of users -


i have query returns list of users. contains current logged in user , make same query without returning user. in models book has foreignkey library called library , library has m2m users called subscribers. it's not important simple query users should work example well.

users = book.library.subscribers.all() 

request.user ends in users , don't want that. know take out of list after making query know if there directly way exclude request.user query.

you can do

book.library.subscribers.exclude(user=request.user)  

assuming, user attribute stores users


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

php - Boolean search on database with 5 million rows, very slow -

css - Text drops down with smaller window -