I want to get a list of all Django auth user with a specific permission group, something like this:
user_dict = {
'queryset': User.objects.filter(permisson='blogger')
}
I cannot find out how to do this. How are the permissions groups saved in the user model?
Try this:
If you want to get list of users by permission, look at this variant:
Groups are many-to-many with Users (you see, nothing unusual, just Django models...), so the answer by cms is right. Plus this works both ways: having a group, you can list all users in it by inspecting
user_set
attribute.(simplified from cms' answer, which I can't edit)
Based on @Glader's answer, this function wraps it up in a single query, and has been modified to algo get the superusers (as by definition, they have all perms):
Based on @Augusto's answer, I did the following with a model manager and using the authtools library. This is in
querysets.py
:And then in
models.py
: