GrantU
GrantU

Reputation: 6555

Django custom user how to now link it FK

I have followed a tutorial on Django's new custom users and created the following...

app accounts:

class CompanyUser(AbstractEmailUser):
    """
    Concrete class of AbstractEmailUser.
    """
    company = models.CharField(max_length=100)

I have another package called pages with a model class Pages, I now need to link the new type of user to this class. As its a separate package what would be the recommended way to do this?

i.e.

Import CompanyUser and set FK as normal? Or create a generic relation on pages class for CompanyUser?

Upvotes: 0

Views: 59

Answers (1)

toad013
toad013

Reputation: 1350

I would put the the relation on the pages object rather than the user object. But if you want to put it there it better to use the AUTH_USER_MODEL from your settings

from django.conf import settings

...

class Pages(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL) # or models.OneToOneField(...)

https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#referencing-the-user-model

Upvotes: 2

Related Questions