vittoriozamboni / django-groups-manager

Manage django groups collection based on django-mptt.
MIT License
100 stars 23 forks source link

Is class User(AbstractUser, MemberMixin) possible? #44

Closed BoPeng closed 4 years ago

BoPeng commented 4 years ago

My application has a customized User class derived from AbstractUser. Instead of defining separate Member class and sync or one to one to User, I am wondering if it is more straightforward to do

class User(AbstractUser, MemberMixin)

so that every user would automatically be a Member.

I understand MemberMixin has some conflicting fields with AbstractUser, so I was basically asking if it is ok to copy the code for MemberMixin into class User, and do something like


class User(AbstractUser, MemberRelationsMixin):
    class GroupsManagerMeta:
        group_model = 'organization.OrganizationGroups'
        group_member_model = 'users.User'
BoPeng commented 4 years ago

I did something like

class User(AbstractUser, MemberRelationsMixin):
    class GroupsManagerMeta:
        group_model = 'users.My_Group'
        group_member_model = 'users.User'

class My_Group(GroupMixin):
    pass

and everything seems to be working all right. I do not need to sync to User.groups since I do not use guardian so the above set up basically allows me to have every user being a Member.

vittoriozamboni commented 4 years ago

Hi Bo! Thank you for the solution you posted. I think it is a great solution the one you found. Glad it worked!

I will take time to test it and will add to the documentation as it seems a very handy use case.

BoPeng commented 4 years ago

Note that when I later tried to squash my migrations to the User model I got some CircularDependencyError because User depends on groups-manager and groups-manager depends on User. It is therefore recommended to migrate the bare User without groups-manager before adding the mixins, which was what I did initially.