在向用户配置文件添加其他字段(如位置、性别、雇主等)时,我是否应该向django.contrib.auth.models.User
添加其他列并将其保存在那里?或者我应该创建一个新表来保存用户配置文件信息?
另外,当用户上传个人资料图片时,我是否应该将其保存在同一张表中?(请注意,这不是生产服务器,我只是在我的本地运行服务器上执行此操作以弄清问题).谢谢
在向用户配置文件添加其他字段(如位置、性别、雇主等)时,我是否应该向django.contrib.auth.models.User
添加其他列并将其保存在那里?或者我应该创建一个新表来保存用户配置文件信息?
另外,当用户上传个人资料图片时,我是否应该将其保存在同一张表中?(请注意,这不是生产服务器,我只是在我的本地运行服务器上执行此操作以弄清问题).谢谢
您必须为用户配置文件制作一个模型:
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'