Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django model, using auth_group as a ForeignKey

I would like to use the auth_group table as a foreign key in my custom model :

class MyModel(models.Model):
    field = models.ForeignKey(auth_group)

I cant find a mention on how to reference this table.

I've seen settings.AUTH_USER_MODEL, but couldnt see anything for auth_group

Any pointers would be appreciated.

like image 932
user2616166 Avatar asked Jun 03 '14 11:06

user2616166


1 Answers

The table auth_group is referenced by the Group model of the auth app, with default naming.

So to make a ForeignKey to an object in that table your model would be:

from django.contrib.auth.models import Group

class MyModel(models.Model):
    field = models.ForeignKey(Group)
like image 124
Dariosky Avatar answered Sep 20 '22 11:09

Dariosky