How add a new field in Group Model of the Django? To use something like
from django.contrib.auth.models import Group
g = Group.objects.get(pk=1)
g.extra_field = "something"
g.save()
it's posssible?
EDIT:
I need a persistent extra field.
How add a new field in Group Model of the Django? To use something like
from django.contrib.auth.models import Group
g = Group.objects.get(pk=1)
g.extra_field = "something"
g.save()
it's posssible?
EDIT:
I need a persistent extra field.
This isn't in the documentation but fine to use (pre to have a basic understanding of monkey patching), in your models.py or init add:
from django.contrib.auth.models import Group
Group.add_to_class('foo', bar)
Where bar can be any python object (or method), e.g.
def bar(self):
return self.attr * 2
or using a field mapping:
Group.add_to_class('foo', models.RegexField(r'^hello$'))
I had the same problem. I wanted to add an extra field in Groups. It worked for me - Monkey patching