0

I want to be able to add a property to the group model

This is what I have been trying

from django.contrib.auth.models import Group

class GroupExtensions(Group):
    class Meta:
       proxy = True

    @property
    def assigned_property(self):
        return 'something'

I want to get this property from the base group model but somehow this doesn't work

group_instance.assigned_property 

Where group_instance is an instance of the Group model

Ahsan
  • 31
  • 1
  • 6

1 Answers1

0

This behaviour is explained here. So the only way for you to be able to use assigned_property is to query the groups through GroupExtensions. But there is a way to make this work, although you should be careful about doing this:

group_instance.__class__ = GroupExtensions
print(group_instance.assigned_property)
Brian Destura
  • 11,487
  • 3
  • 18
  • 34
  • Oh I believe then the only way to achieve it is by tweaking the rules Thanks for the help Really appreciated :) – Ahsan Jul 08 '21 at 13:03