Django 用户个人资料 [英] Django user profile

查看:38
本文介绍了Django 用户个人资料的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

向用户配置文件添加其他字段(例如位置、性别、雇主等)时,我是否应该向 django.contrib.auth.models.User 添加其他列并将其保存在那里?或者我应该创建一个新表来保存用户个人资料信息?

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

然后在settings.py中配置:

AUTH_PROFILE_MODULE = 'accounts.UserProfile'

这篇关于Django 用户个人资料的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆