How do I extend the Django Group model?

If you simply subclass the Group object then by default it will create a new database table and the admin site won’t pick up any new fields.

You need to inject new fields into the existing Group:

if not hasattr(Group, 'parent'):
    field = models.ForeignKey(Group, blank=True, null=True, related_name="children")
    field.contribute_to_class(Group, 'parent')

To add methods to the Group, subclass but tag the model as proxy:

class MyGroup(Group):

    class Meta:
        proxy = True

    def myFunction(self):
        return True

Leave a Comment