Reputation: 1404
I have the following model field:
name = models.ForeignKey(User, unique=False, editable=False, limit_choices_to=
{'is_staff': False})
How can I limit the choices based on a specific group of users as opposed to limiting to specific users based on a flag. Is it possible to somehow limit choices based on auth_user_groups?
Thanks
Upvotes: 13
Views: 4510
Reputation: 11832
Yes, you can limit choices based on groups, here is one example
user = models.ForeignKey(User, unique=False, limit_choices_to= Q( groups__name = 'GroupName') )
try this, it works!
Upvotes: 14