그래서 나는 django에서 일반적인 "accounts"페이지를 만들고 있습니다. 장고 등록 플러그인을 사용했고, 현재 (djang-standard) User 객체와 UserProfile 및 UserProfileForm 객체를 가지고 있습니다.django edit user와 userprofile 객체
이것은 스타일이나 모범 사례에 대한 질문입니다. 내가 "옳은"계획을 세우고 있거나 이것을 수행하는 "더 나은/추천/표준 방법"이 있습니까?
무엇 내가 request.user의 예에서 사용자 프로필 만드는 일을 계획입니다 :
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']
:
form = UserProfileForm(instance=User)
을 (그리고보기에 그 형태를 전송) 및 UserProfileForm에서 내 USERPROFILE 거의 그렇게 같다
:
class UserProfile(models.Model):
user = models.OneToOneField(User)
points = models.IntegerField(default=0) #how is the user going with scores?
및 사용자는의입니다다양한.
편집 및 저장 처리 중 하나를 mixin
django 물건을 통해 수행됩니다 또는 더 많은 가능성이 있기 때문에 내가 게시물을 가져오고 가져옵니다 핸들을 내 자신의 사용자 정의보기를 mixins 읽었습니다. 그러나 믹스 인을 사용해야한다고 확신하기 때문에 위의 "맞습니까?" 또는 제안이 있습니까?
건배!
및 get_profile가 사용되지 않습니다 : 새 사용자를 만들려면, 단지 사용자 생성자를 호출 – Jay