0

I want to be able to efficiently find all user with a particular permission and then among those users find all users who have a particular flag (I extended the base User model and created my own, which has the flag). I was wondering what is the easiest/efficient way to do this? I was reading the below (among other sites):

How can I get all objects a user has specific permissions to in django guardian?

But they dont seem to be helping in my situation. Please let me know if there is an article I missed, thanks!

[EDIT]

I read the following page:

http://digitaldreamer.net/blog/2010/5/10/get-all-users-group-django/

Basically I want to get all users who have a particular permission AND who have a certain flag. Right now I can do: User.objects.filter(organization_id = id) to get all users within a particular organization as per my code. But within that list, I want all users who have a particular permission.

Community
  • 1
  • 1
KVISH
  • 12,923
  • 17
  • 86
  • 162

2 Answers2

1

I asked a question related to django-guardian and answered it myself after much research. I believe you should be able to find your answer here: Django Groups and Permissions. Extending Groups to have a FK?

UPDATE

You could do something like this:

user_list = []
for user in User.Objects.filter(organization_id=id):
    if user.has_perm('PERM NAME'):
        user_list.append(user)

See this link for more details: http://packages.python.org/django-guardian/userguide/check.html

Community
  • 1
  • 1
super9
  • 29,181
  • 39
  • 119
  • 172
  • Not sure if I am misunderstanding what you have written there...but I dont think it's for the same purpose I'm trying to solve? I updated my question. – KVISH Jul 07 '12 at 18:25
0

You could do it as mentioned above. But by chaining filter statements, it is also possible. I referred to this other question: How to get a list of all users with a specific permission group in Django. By chaining both filter statements, I can get all users with a permission and all users with the certain organization_id.

Community
  • 1
  • 1
KVISH
  • 12,923
  • 17
  • 86
  • 162