ModelName(django.contrib.auth.models.User) vs ModelName(models.Model)
Posted
by
amr.negm
on Stack Overflow
See other posts from Stack Overflow
or by amr.negm
Published on 2011-11-20T17:46:05Z
Indexed on
2011/11/20
17:53 UTC
Read the original article
Hit count: 218
I am developing a django project. I created some apps, some of those are related to User model, for instance, I have a feeds app that handles user feeds, and another app that deals with extra user data like age, contacts, and friends. for each of these, I created a table that should be connected to the User model, which I using for storing and authenticating users.
I found two ways to deal with this issue. One, is through extending User model to be like this:
ModelName(User):
friends = models.ManyToMany('self')
.....
Two, is through adding a foreign key to the new table like this:
ModelName(models.Model):
user = models.ForeignKey(User, unique=True)
friends = friends = models.ManyToMany('self')
......
I can't decide which to use in which case. in other words, what are the core differences between both?
© Stack Overflow or respective owner