Django, filter users by group in a model foreign key

I have a model for a blog post where the owner of the post is the foreign key for the user. With this model, any user can own a blog. I would like to change it so that only users in a specific -let group call it "bloggers" - they can own the blog object. Ideally, this should also appear in the admin, I mean in the blog administrator right now, all users are listed in the menu for the "owner", he should list only those that are in the group of "bloggers". How to do this with Django 1.3?

+6
source share
1 answer

Use limit_choices_to paramether in the ForeignKey definition as follows:

 author = models.ForeignKey("auth.User", limit_choices_to={'groups__name': "bloggers"}) 
+13
source

Source: https://habr.com/ru/post/918550/


All Articles