AttributeError at /account/register/
type object 'UserProfile' has no attribute 'USERNAME_FIELD'
Вот сама модель:
class UserProfile(models.Model):
user = models.OneToOneField(User)
username = models.CharField(max_length=100, default='')
first_name = models.CharField(max_length=100, default='')
last_name = models.CharField(max_length=100, default='')
email = models.EmailField()
password1 = models.CharField(max_length=50)
description = models.CharField(max_length=100, default='')
city = models.CharField(max_length=100, default='')
website = models.URLField(default='')
phone = models.IntegerField(default=0)
image = models.ImageField(upload_to='profile_image', blank=True)
london = UserProfileManager()
def __str__(self):
return self.user.username
Форма:
class RegistrationForm(UserCreationForm):
class Meta:
model = UserProfile
fields = (
'username',
'first_name',
'last_name',
'email',
'password1',
'description',
'city',
'website',
'phone',
'image',
)
def save(self, commit=True):
user = super(RegistrationForm, self).save(commit=False)
user.description = self.cleaned_data['description']
user.username = self.cleaned_data['username']
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
user.email = self.cleaned_data['email']
user.password1 = self.cleaned_data['password1']
user.city = self.cleaned_data['city']
user.website = self.cleaned_data['website']
user.phone = self.cleaned_data['phone']
user.image = self.cleaned_data['image']
if commit:
user.save()
return user
View:
def register(request):
if request.method =='POST':
form = RegistrationForm(request.POST)
if form.is_valid():
new = form.save(commit=False)
new.save()
# return redirect(reverse('accounts:home'))
return redirect('/home/')
else:
form = RegistrationForm()
args = {
'form': form,
}
return render(request, 'accounts/reg_form.html', args)