Note that there are some explanatory texts on larger screens.

plurals
  1. POIn Django how do I pass the request parameters a signal_handler which save the Profile of User when the user_save signal is called?
    text
    copied!<p>I am having problem saving additional information about each user automatically when a new user signs-up. I have created a profile for User model extension to save additional data about my users. However, when the signal handler gets called at post_save, the data stored in the request is not passed to the signal_handler. </p> <p>The following is the profile that I have created.</p> <pre><code>class StudentProfile(models.Model): user = models.ForeignKey(User, unique=True) # Other information about the Student city = models.CharField(max_length=25) country = models.CharField(max_length=25) student_age = models.IntegerField(max_length=3) </code></pre> <p>In my signup view I call form.save() function in which the User object gets created and a new row is added in the data base. </p> <pre><code>def save(self, new_data): u = User.objects.create_user( new_data['username'], new_data['email'], new_data['password']) return u </code></pre> <p>After that, the post_save signal is called and the signal handler tries to create a new profile:</p> <pre><code>def create_student_profile(sender, instance, created, **kwargs): if created: StudentProfile.objects.create(user=instance) post_save.connect(create_student_profile, sender=User) </code></pre> <p>At this point, I get the following error in the broswer:</p> <p><strong>IntegrityError at /signup/ (1048, "Column 'student_age' cannot be null")</strong></p> <p>I looked at the call stack and found that the SQL query that is being executed has None value for Student_age and nothing for country and city.</p> <p>sql u'INSERT INTO <code>student_studentprofile</code> (<code>user_id</code>, <code>city</code>, <code>country</code>, <code>student_age</code>) VALUES (17, , , None)'</p> <p>How can I pass the request parameters such as student_age, country and city to this signal handler? Do I have to manually save this information? </p> <p>I have thoroughly searched for the answer of this question on stackOverflow and Google and I have come rather empty handed.</p> <p>Thanks for your help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload