How to integrate groups with AbstractBaseUser in django?












1














How can I add group capabilities to my custom django user model? I seen that I'm able to inherit the PermissionsMixin but I do not see any group functionality in doing so. Basically, I need to be able to add custom groups to the custom user model.










share|improve this question






















  • Just inherit PermissionsMixin and create your custom group user.grooups.add(Group.objects.create(name='mycustomgroup'). Or you want something else?
    – sinitsynsv
    Sep 21 '15 at 5:35












  • PermissionsMixin - is an abstract model, it has groups field, which is ManyToMany field to auth.Group model (read the docs about it). To create custom group - you call group = Group.objects.create(name='mycustomgroup'). Also you can assign permissions to group: group.permissions.add(Persmission.objects.get(codename='myapp.add_mymodel') To assign group to user you use this user.groups.add(group).
    – sinitsynsv
    Sep 21 '15 at 8:31
















1














How can I add group capabilities to my custom django user model? I seen that I'm able to inherit the PermissionsMixin but I do not see any group functionality in doing so. Basically, I need to be able to add custom groups to the custom user model.










share|improve this question






















  • Just inherit PermissionsMixin and create your custom group user.grooups.add(Group.objects.create(name='mycustomgroup'). Or you want something else?
    – sinitsynsv
    Sep 21 '15 at 5:35












  • PermissionsMixin - is an abstract model, it has groups field, which is ManyToMany field to auth.Group model (read the docs about it). To create custom group - you call group = Group.objects.create(name='mycustomgroup'). Also you can assign permissions to group: group.permissions.add(Persmission.objects.get(codename='myapp.add_mymodel') To assign group to user you use this user.groups.add(group).
    – sinitsynsv
    Sep 21 '15 at 8:31














1












1








1







How can I add group capabilities to my custom django user model? I seen that I'm able to inherit the PermissionsMixin but I do not see any group functionality in doing so. Basically, I need to be able to add custom groups to the custom user model.










share|improve this question













How can I add group capabilities to my custom django user model? I seen that I'm able to inherit the PermissionsMixin but I do not see any group functionality in doing so. Basically, I need to be able to add custom groups to the custom user model.







django django-models






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 21 '15 at 5:22









user1529891user1529891

4,83293574




4,83293574












  • Just inherit PermissionsMixin and create your custom group user.grooups.add(Group.objects.create(name='mycustomgroup'). Or you want something else?
    – sinitsynsv
    Sep 21 '15 at 5:35












  • PermissionsMixin - is an abstract model, it has groups field, which is ManyToMany field to auth.Group model (read the docs about it). To create custom group - you call group = Group.objects.create(name='mycustomgroup'). Also you can assign permissions to group: group.permissions.add(Persmission.objects.get(codename='myapp.add_mymodel') To assign group to user you use this user.groups.add(group).
    – sinitsynsv
    Sep 21 '15 at 8:31


















  • Just inherit PermissionsMixin and create your custom group user.grooups.add(Group.objects.create(name='mycustomgroup'). Or you want something else?
    – sinitsynsv
    Sep 21 '15 at 5:35












  • PermissionsMixin - is an abstract model, it has groups field, which is ManyToMany field to auth.Group model (read the docs about it). To create custom group - you call group = Group.objects.create(name='mycustomgroup'). Also you can assign permissions to group: group.permissions.add(Persmission.objects.get(codename='myapp.add_mymodel') To assign group to user you use this user.groups.add(group).
    – sinitsynsv
    Sep 21 '15 at 8:31
















Just inherit PermissionsMixin and create your custom group user.grooups.add(Group.objects.create(name='mycustomgroup'). Or you want something else?
– sinitsynsv
Sep 21 '15 at 5:35






Just inherit PermissionsMixin and create your custom group user.grooups.add(Group.objects.create(name='mycustomgroup'). Or you want something else?
– sinitsynsv
Sep 21 '15 at 5:35














PermissionsMixin - is an abstract model, it has groups field, which is ManyToMany field to auth.Group model (read the docs about it). To create custom group - you call group = Group.objects.create(name='mycustomgroup'). Also you can assign permissions to group: group.permissions.add(Persmission.objects.get(codename='myapp.add_mymodel') To assign group to user you use this user.groups.add(group).
– sinitsynsv
Sep 21 '15 at 8:31




PermissionsMixin - is an abstract model, it has groups field, which is ManyToMany field to auth.Group model (read the docs about it). To create custom group - you call group = Group.objects.create(name='mycustomgroup'). Also you can assign permissions to group: group.permissions.add(Persmission.objects.get(codename='myapp.add_mymodel') To assign group to user you use this user.groups.add(group).
– sinitsynsv
Sep 21 '15 at 8:31












1 Answer
1






active

oldest

votes


















1














If your custom django user model inherit from AbstractUser,
by default it already inherits the PermissionsMixin



from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin

class AbstractUser(AbstractBaseUser, PermissionsMixin):
"""
An abstract base class implementing a fully featured User model with
admin-compliant permissions.

Username, password and email are required. Other fields are optional.
"""
username = models.CharField(_('username'), max_length=30, unique=True,
...


So, u can use the default groups options.



Documentation






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32687879%2fhow-to-integrate-groups-with-abstractbaseuser-in-django%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    If your custom django user model inherit from AbstractUser,
    by default it already inherits the PermissionsMixin



    from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin

    class AbstractUser(AbstractBaseUser, PermissionsMixin):
    """
    An abstract base class implementing a fully featured User model with
    admin-compliant permissions.

    Username, password and email are required. Other fields are optional.
    """
    username = models.CharField(_('username'), max_length=30, unique=True,
    ...


    So, u can use the default groups options.



    Documentation






    share|improve this answer




























      1














      If your custom django user model inherit from AbstractUser,
      by default it already inherits the PermissionsMixin



      from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin

      class AbstractUser(AbstractBaseUser, PermissionsMixin):
      """
      An abstract base class implementing a fully featured User model with
      admin-compliant permissions.

      Username, password and email are required. Other fields are optional.
      """
      username = models.CharField(_('username'), max_length=30, unique=True,
      ...


      So, u can use the default groups options.



      Documentation






      share|improve this answer


























        1












        1








        1






        If your custom django user model inherit from AbstractUser,
        by default it already inherits the PermissionsMixin



        from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin

        class AbstractUser(AbstractBaseUser, PermissionsMixin):
        """
        An abstract base class implementing a fully featured User model with
        admin-compliant permissions.

        Username, password and email are required. Other fields are optional.
        """
        username = models.CharField(_('username'), max_length=30, unique=True,
        ...


        So, u can use the default groups options.



        Documentation






        share|improve this answer














        If your custom django user model inherit from AbstractUser,
        by default it already inherits the PermissionsMixin



        from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin

        class AbstractUser(AbstractBaseUser, PermissionsMixin):
        """
        An abstract base class implementing a fully featured User model with
        admin-compliant permissions.

        Username, password and email are required. Other fields are optional.
        """
        username = models.CharField(_('username'), max_length=30, unique=True,
        ...


        So, u can use the default groups options.



        Documentation







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 20 '18 at 15:24









        cardamom

        1,82111338




        1,82111338










        answered Sep 21 '15 at 5:50









        Paulo PessoaPaulo Pessoa

        1,8571226




        1,8571226






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32687879%2fhow-to-integrate-groups-with-abstractbaseuser-in-django%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]