At some point of building your project you may wish to allow users to store some extra data. If you use Django‘s built-in authentication system you are in luck - much of the code have been already written and you only have to:
For convenience, richtemplates comes with basic UserProfile class. You may use it directly by adding following line in your settings:
This model provides only most basic fields:
However, more probably you would like to extend this class - simply follow guidelines described at Subclassing profile class.
If needed (well, most probably it is needed in one’s project) UserProfile may be easy subclassed. Let’s say we have main application where we define our user profile model and app label is core. We need to add address field at profile model. Models code could look as follows:
from django.db import models from richtemplates.models import UserProfile as RichUserProfile class UserProfile(RichUserProfile): address = models.CharField(max_length=128, null=True, blank=True)
Then, at settings file of our project we need to point at this class:
AUTH_PROFILE_MODULE = 'core.UserProfile'
If we create pluggable application and want to make our user profile class abstract until AUTH_PROFILE_MODULE is pointed at our model, we can add simple check within Meta class of our model:
from django.conf import settings from django.db import models from richtemplates.models import UserProfile as RichUserProfile class UserProfile(RichUserProfile): address = models.CharField(max_length=128, null=True, blank=True) class Meta: abstract = getattr(settings, 'AUTH_PROFILE_MODULE', '') != \ 'core.UserProfile'