title: How to extend django User model properly
body: <p>Here i am trying to add profile model fields along with user model fields.But it not working it doesn't add the profile models data.But <code>after adding</code> when i do update the user i can update both model <code>user</code> and <code>profile</code> together.But while registering the user i am not being able to add <code>profile</code> models data .Is it possible to add profile model data along with user model at a time ?</p>
  
  <blockquote>
    <p>models.py</p>
  </blockquote>
  
  <pre><code>class Profile(models.Model):
      user = models.OneToOneField(User, on_delete=models.CASCADE)
      first_name = models.CharField(max_length=100,blank=True,null=True)
      last_name = models.CharField(max_length=100,blank=True, null=True)
      location = models.CharField(max_length=100,blank=True, null=True)
      phone = models.CharField(max_length=20,blank=True,null=True)
      image = models.ImageField(upload_to='user image',default='default.jpg')
  
  
      @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()
  </code></pre>
  
  <blockquote>
    <p>forms.py</p>
  </blockquote>
  
  <pre><code>class RegisterForm(UserCreationForm):
      first_name = forms.CharField(max_length=100, required=False)
      last_name = forms.CharField(max_length=100, required=False)
      location = forms.CharField(max_length=100, required=False)
      phone = forms.CharField(max_length=20, required=False)
      image = forms.FileField(required=False, initial='default.jpg')
  
      def clean_email(self):
          email = self.cleaned_data['email']
          if User.objects.filter(email=email).exists():
              raise ValidationError('Email Already Exists')
  
          return email
  
      class Meta:
          model = User
          fields = ['username', "email", "password1", "password2",'first_name','last_name','location','phone','image','is_superuser', 'is_staff', 'is_active']
  </code></pre>
  
  <blockquote>
    <p>views.py</p>
  </blockquote>
  
  <pre><code>def add_user(request):
      if request.method == "POST":
          form = RegisterForm(request.POST or None,request.FILES or None)
          if form.is_valid():
              user = form.save(commit=False)
              user.save()
              messages.success(request, 'user created with username {}'.format(user.username))
              return redirect('list_user')
      else:
          form = RegisterForm()
      return render(request, 'add_user.html', {'form': form})
  
  def update_user(request, id): #the problem while  updating is if i don't select the new image then it saves the default image.But other works fine
      user = get_object_or_404(User, id=id)
      if request.method == 'POST':
  
          form = EditRegisterForm(request.POST or None,request.FILES or None,instance=user)
          if form.is_valid():
              phone = form.cleaned_data['phone']
              location = form.cleaned_data['location']
              image = form.cleaned_data['image']
              first_name = form.cleaned_data['first_name']
              last_name = form.cleaned_data['last_name']
              user = form.save(commit=False)
              user.profile.phone = phone
              user.profile.location = location
              user.profile.first_name = first_name
              user.profile.last_name = last_name
              user.profile.image = image
              user.save()
              messages.success(request, ' {}  updated.'.format(user.username))
              return redirect('list_user')
  </code></pre>
  
  <blockquote>
    <p>add_user.html</p>
  </blockquote>
  
  <pre><code> &lt;form action="" method="post" enctype="multipart/form-data"&gt;
                              {% csrf_token %}
                               {% bootstrap_form form %}
                              &lt;div&gt;
                                  &lt;button type="submit" class="btn btn-info"&gt;Add&lt;/button&gt;
                              &lt;/div&gt;
                          &lt;/form&gt;
  </code></pre>