2016-08-13 2 views
0

처음으로 userena를 장고에서 사용했습니다. 내가 userena의 가입 양식을 무시하고 지금 오류가 있습니다.'SignupFormExtra'개체에 '_meta'속성이 없습니다

from userena import settings as userena_settings 
from userena.models import UserenaSignup 
from userena.utils import get_profile_model 

class SignupFormExtra(SignupForm): 
""" 
A form to demonstrate how to add extra fields to the signup form, in this 
case adding the first and last name. 


""" 
cellPhone = forms.CharField(label=_(u'CellPhone'), 
          max_length=30, 
          required=False) 
first_name = forms.CharField(label=_(u'First name'), 
          max_length=30, 
          required=False) 

last_name = forms.CharField(label=_(u'Last name'), 
          max_length=30, 
          required=False) 

def save(self): 
    """ 
    Override the save method to save the first and last name to the user 
    field. 

    """ 
    # First save the parent form and get the user. 
    new_user = super(SignupFormExtra, self).save() 

    # Get the profile, the `save` method above creates a profile for each 
    # user because it calls the manager method `create_user`. 
    # See: https://github.com/bread-and-pepper/django-userena/blob/master/userena/managers.py#L65 
    new_user = get_profile_model() 

    new_user.first_name = self.cleaned_data['first_name'] 
    new_user.last_name = self.cleaned_data['last_name'] 
    new_user.cellPhone = self.cleaned_data['cellPhone'] 
    new_user.save(self) 

    # Userena expects to get the new user from this form, so return the new 
    # user. 
    return new_user 

사실 난 model.py에서 클래스 프로파일을 가지고 같은 userena 언급 :

class Profile(UserenaBaseProfile): 
user = models.OneToOneField(User, 
          on_delete=models.CASCADE, 
          unique=True, 
          verbose_name=_('user'), 
          related_name='my_profile') 

이 사람이 내가 그것을 해결하는 데 도움이 될 수 있습니다?

답변

1

당신은이 부분 필요가없는 : 그냥 저장하고 new_user.save에서()

new_user.save (자신을) 자기를 제거, 당신은 이전 명령에서 NEW_USER을 얻을

new_user = get_profile_model() 

을 -> new_user.save()

def save(self): 
    """ 
    Override the save method to save the first and last name to the user 
    field. 

    """ 
    # First save the parent form and get the user. 
    new_user = super(SignupFormExtra, self).save() 
    new_user.first_name = self.cleaned_data['first_name'] 
    new_user.last_name = self.cleaned_data['last_name'] 
    new_user.cellPhone = self.cleaned_data['cellPhone'] 
    new_user.save() 

    # Userena expects to get the new user from this form, so return the new 
    # user. 
    return new_user