Reputation: 777
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:
class Organization(Group):
url = models.CharField(max_length=100)
However when using this organization and adding it to a user (by using org.user_set.add(user)
) I have no way of accessing the url field from the User. When I do user.groups.all()
it shows the user is in a Group (not Organization) with the same name I set on my organization org
. So how I do I add functionality to Group but keep it accessible from my user info?
Upvotes: 4
Views: 4821
Reputation: 1137
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.
Upvotes: 6