Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8037169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:50:48+00:00 2026-06-05T02:50:48+00:00

The following form always returns UserProfile matching query does not exist. though I configured

  • 0

The following form always returns UserProfile matching query does not exist. though I configured the signal.

And it works like expected from the inetrpreter.

In [1]: from core.models import User

In [2]: u = User.objects.get(id = 1)

In [3]: user_address = u.get_profile().home_address

In [4]: user_address = '20 St.'

Model

from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save

class UserProfile(models.Model):
    url = models.URLField()
    home_address = models.TextField()
    user = models.ForeignKey(User, unique=True)


def create_user_profile(sender, instance, created, **kwargs):
    if created:
        UserProfile.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)

View

from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User, Group
from django import forms
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.template.context import RequestContext
from django.views.decorators.csrf import csrf_protect

class RegisterForm(UserCreationForm):
    """
    Hacking the UserCreationForm class by creating a child class,
    and overriding the save mthod .save().
    Now it should provide email, first_name and last_name fields.
    """
    permission_choices = (
            ('1', 'test1'),
            ('2', 'test2'),
            )
    email      = forms.EmailField(required=False)
    first_name = forms.CharField(required=False)
    last_name  = forms.CharField(required=False)
    url        = forms.URLField()
    permission = forms.ChoiceField(choices=permission_choices)

    class Meta(UserCreationForm.Meta):
        model = User
        fields = ('first_name', 'last_name', 'url', 'username', 'email', 'password1', 'password2', 'permission')

    def save(self, commit=True):
        user = super(RegisterForm, self).save(commit=False)
        user_profile    = user.get_profile()
        user.email      = self.cleaned_data['email']
        user.first_name = self.cleaned_data['first_name']
        user.last_name  = self.cleaned_data['last_name']
        user.permission = self.cleaned_data['permission']
        user_profile.url = self.cleaned_data['url']
        if commit:
            user.save()
            user_profile.save()
        return user

@csrf_protect
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            if new_user.permission == '1':
                try:
                    new_user.groups.add(Group.objects.get(name='test1'))
                except Group.DoesNotExist:
                    u = User.objects.get(pk=new_user.pk)
                    u.delete()
                    return HttpResponse('The Organisation you\'ve just choosed doesn\' exist')
            return HttpResponse('OK')
    else:
        form = RegisterForm()

    return render_to_response('registration/user.html', {'form': form}, context_instance=RequestContext(request))

Like what cberner said, I think it’s because:

I believe you’re getting that error because you call
super(RegisterForm, self).save(commit=False). If you use commit=False
Django wouldn’t emit a post_save signal, since the model isn’t
actually committed to the database.

Here’s the solution:

def save(self, commit=True):
    user = super(RegisterForm, self).save(commit=False)
    user.email      = self.cleaned_data['email']
    user.first_name = self.cleaned_data['first_name']
    user.last_name  = self.cleaned_data['last_name']
    user.permission = self.cleaned_data['permission']
    user.save()

    user_profile    = UserProfile(user=user, url=self.cleaned_data['url'])
    if commit:
        user_profile.save()
    return user
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:50:50+00:00Added an answer on June 5, 2026 at 2:50 am

    I believe you’re getting that error because you call super(RegisterForm, self).save(commit=False). If you use commit=False Django wouldn’t emit a post_save signal, since the model isn’t actually committed to the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason the following form isn't submitting the file like it should and
I have the following code which works in Internet Explorer, but not in Firefox
I have following form: class EmailPreferences(forms.ModelForm): Base form used for fields that are always
I have the following form, which I have reduced as much as I can,
I have the following form for photo_album which uses the nested forms feature of
I have the following form <form name=myForm id=myForm method=post enctype=multipart/form-data action=script.php> and this jQuery
I have done the following form <% form_for @anexo, :url => {:action => create},
I have the following form code: # forms.py class SomeForm(forms.Form): hello = forms.CharField(max_length=40) world
i have the following form item { fieldLabel:'Username' ,id:username ,name:'username' ,allowBlank:false ,plugins:[Ext.ux.plugins.RemoteValidator] ,rvOptions: {
I have strings of following form a = x + y or abc =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.