Search code examples
djangodjango-formsdjango-registration

Accessing a Form's cleaned data from a signals callback?


I've been following the tutorial from this link and it's working perfectly:

http://johnparsons.net/index.php/2013/06/28/creating-profiles-with-django-registration/

My only problem however is this line from the user_registered_callback method:

profile.is_human = bool(request.POST["is_human"])

Because it's accessing the request variable directly (if you remove the bool function).

How do I do it so the value I'm passing to my model is already validated by the referring form?


Solution

  • The form instance is not passed to this signal so I am afraid that you have to validate the data again:

    def user_registered_callback(sender, user, request, **kwargs):
    
        form = ExRegistrationForm(request.POST)
        form.full_clean()
    
        profile = ExUserProfile(user=user)
        profile.is_human = form.cleaned_data['is_human']
        profile.save()