Feb-20-2019, 05:10 PM
(This post was last modified: Feb-20-2019, 05:10 PM by m0ntecr1st0.)
After registration I get error. In admin page I see, that user is created, but profile doesn't exist.
I see, that
Sory for my bad english
forms.py
signals.py
I see, that
user
has attribute profile
, but when I want to see dir(user.profile)
, I don't nothing see.Sory for my bad english

forms.py
from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.models import User class SignupForm(UserCreationForm): phone = forms.CharField() fax = forms.CharField(required=False) class Meta: model = User fields = ('username','first_name', 'phone', 'fax', 'password1', 'password2')views.py
def signup(request): if request.method == 'POST': form = SignupForm(request.POST, request.FILES) if form.is_valid(): phone = form.cleaned_data.get('phone') fax = form.cleaned_data.get('fax') user = form.save(commit=False) user.is_active = False user.save() #Here is the error profile = user.profile profile.phone = phone profile.fax = fax profile.save() else: form = SignupForm()models.py
class Profile(models.Model): user = models.OneToOneField(User) phone = models.CharField(max_length=40, verbose_name='Phone') fax = models.CharField(max_length=40, verbose_name='Fax', blank=True, null=True)
signals.py
@receiver(post_save, sender=User) def create_user_profile(sender, instance, created, **kwargs): if created: Profile.objects.create(user=instance) @receiver(post_save, sender=User) def save_user_profile(sender, instance, **kwargs): instance.profile.save()apps.py
# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.apps import AppConfig class ProfilesConfig(AppConfig): name = 'profiles' def ready(self): import profiles.signals