djangodjango-formsdjango-registrationdjango-usersdjango-profiles

Do I need to override save method to add data to different models from django UserCreationForm


I want to add another field in UserCreationForm to be shown in RegistrationForm , I saw a couple of examples on stackoverflow for that purpose. I mean the examples by defining different RegisterForm inherited from UserCreationForm as explained in this question of stackoverflow: django-create-custom-usercreationform-basic

But what will I do, if my data belongs to 2 or 3 different models including User model? Will I then override save method or do some other thing? Is there some way to handle it without going to more low level by just handling it in RegistrationForm that will be inherited from UserCreationForm? What is better way?


Solution

  • Okay, like you see in the link, there are many approaches which you can use, no one of them looks such highlevel as you want. I don't know how familiar you are with Django, but the linked appraoch looks very promising. It's fresh, uses the signals framework (flexible) and is very easy to implement - high level enough for your problem. Look out for UserProfile Examples because they are very similiar to your Problem and more usual.

    If you don't want to go the way with signals, the most straight-forward solution would be to override the save method.

    So you already had the solutions in mind. Imho I can't figure out a better or more high level solution.