所以我在django中制作了一个通用的“帐户”页面。我使用了django-registration插件,目前有一个(djang标准)User对象,以及一个UserProfile和UserProfileForm对象。django编辑用户和用户配置文件对象
这是一个风格问题,或我认为最佳做法。我正在计划“正确”还是有一个“更好/推荐/标准的方式”来做到这一点?
什么我打算做的是创建一个从request.user即用户配置:
form = UserProfileForm(instance=User)
(和发送该表单的视图),并在UserProfileForm:
class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
def __init__(self,*args,**kwargs):
super(UserProfileForm, self).__init__(*args, **kwargs)
if kwargs.has_key('instance'):
self.user = kwargs['instance']
在我的用户配置是相当多的,像这样:
class UserProfile(models.Model):
user = models.OneToOneField(User)
points = models.IntegerField(default=0) #how is the user going with scores?
并在用户是的品种。
好的!编辑和保存的处理将通过mixin
django的东西完成,或者更可能是因为我没有阅读mixin我自己的用户定义的视图来处理帖子和获取。但忽略这一点 - 因为我确定我应该使用混合 - 是上面的“对吗?”还是有建议?
干杯!
FYI今天,AUTH_PROFILE_MODULE和get_profile已被弃用 – Jay