0

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?

Community
  • 1
  • 1
Hafiz
  • 4,187
  • 12
  • 58
  • 111
  • check out this [link](http://dmitko.ru/django-registration-form-custom-field/) – seb Apr 11 '12 at 00:11
  • @seb so it is similar 2 times inherited from userCreationForm or like writing own save function – Hafiz Apr 11 '12 at 01:07
  • I don't get your point exactly, because you use Names as if they were usal or common. Provide an example or explain it better. – seb Apr 11 '12 at 16:06
  • @seb you understood it correctly and gave the right link that has what I wanted to do, I just wanted to know if there is a high level way without going into writing `backend` or writing own `save` method – Hafiz Apr 11 '12 at 17:14

1 Answers1

0

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.

Community
  • 1
  • 1
seb
  • 4,279
  • 2
  • 25
  • 36
  • If I use it like http://stackoverflow.com/questions/5745197/django-create-custom-usercreationform-basic then will I use `RegistrationForm` class or `UserCreationForm` class in register function of my view? – Hafiz Apr 15 '12 at 17:52
  • You have to use of course your specialized class, look how [OOP](http://en.wikipedia.org/wiki/Object-oriented_programming) works. That means u have to use RegistrationForm. – seb Apr 16 '12 at 18:14
  • ok thanks, I understand OOP but just was confuse because of new environment. – Hafiz Apr 16 '12 at 21:14