How to extend Django Group and still use in Django User

前端 未结 1 563
孤城傲影
孤城傲影 2021-02-10 16:13

I am looking to extend the functionality of Django\'s group, so I can have extra properties on the Group such as a url for the Group\'s homepage. Something like this:

         


        
1条回答
  •  忘掉有多难
    2021-02-10 16:52

    You have two option;

    1) New model;

    class GroupProfile(models.Model):
        group = models.OneToOneField('auth.Group', unique=True)
        url = models.CharField(max_length=100)
    

    2) Monkey Patch;

    Group.add_to_class('url', models.CharField(max_length=100))
    

    In second option you have to use app like south for db migration.

    0 讨论(0)
提交回复
热议问题