I have one understanding probem:
I want to create user profile for my page, which will have many attributes. But since I am new to User Model of django's auth, i dont know if i can extend that model with new coming attributes that i set for user profile. e.g. address, age, ...
if not, why is User Model there? is it only for auth purposes? how do I handle and differentiate these two User models?
Sample Case:
user wants to log in, I check the permission with auth's user model and set some relation between django's user model and mine? I just kind of confused here
I shall try to explain in the perspective of pre-django 1.5
The django's auth models provides a set of "convenience" methods like login, logout, password reset, etc for you which work seamlessly. It is a very common scenario to have more fields - so One approach would be to create a userprofile model, which either inherits
from the django auth user model, or has a OneToOne
relationship on the same. This way, you do not have to reimplement some of the already implemented features. In addition, there is groups
and permissions
models in the package which add a whole layer of functionality in terms of user permissionsing.
example:
from django.contrib.auth.models import User
class MyCustomProfile(User):
#inherits all the attributes of default `User` models
#additional models here.
OR
from django.contrib.auth.models import User
class MyCustomProfile(models.Model):
user = models.OneToOneField(User)
#additional models here.
This way, you can use the all the features and build on top of it.
This has changed a little bit in django-1.5 which lets users have Custom fields, which saves you from creating a UserProfile
model on top of the already existing User
model.