When adding additional fields to a user profile, such as location, gender, employer, etc., should I be adding additional columns to django.contrib.auth.models.User
and saving it there? Or should I be creating a new table to save user profile information?
Also, when a user uploads a profile picture, should I be saving this in the same table? (Note this is not a production server, I'm just doing this on my local runserver to figure things out). Thank you
You have to make a model for the user profile:
class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) location = models.CharField(max_length=140) gender = models.CharField(max_length=140) employer = models.ForeignKey(Employer) profile_picture = models.ImageField(upload_to='thumbpath', blank=True) def __unicode__(self): return u'Profile of user: %s' % self.user.username
Then configure in settings.py
:
AUTH_PROFILE_MODULE = 'accounts.UserProfile'
Conceptually, OneToOneField is similar to a ForeignKey with unique=True, but the “reverse” side of the relation will directly return a single object. This is the recommended way of extending User class.
class UserProfile(models.Model): user = models.OneToOneField(User) ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With