-1

I am trying to develop a register based website. I used django registration redux for it. But I can't figure out how to modify it. As an example in default files there are username and password, I want to change username with an e-mail and add additional form to it.

Thanks in advance

Hamlock B
  • 27
  • 1
  • 7

1 Answers1

1

Step 1 - customize User model:

1.1 add next lines to your settings file:

AUTH_USER_MODEL = 'my_accounts_app.MyUser'

1.2 don't forget add your application with User model to INSTALLED_APPS:

INSTALLED_APPS = (
   ...
   'my_accounts_app',
)

1.3 write custom User model:

class MyUser(AbstractBaseUser):

   # some fields here

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = [...]

Step 2 - customize django-registration form (if you need it):

2.1 Write your own registration form.

2.2 Then you need to use your form. There is you can use 2 options:

a) you can write custom registration view based on registration.views.RegistrationView and pass "form_class" attribute to your view

b) OR you can set your custom registration form via passing it in your urls.py There is the link to related django doc Django URLconf usage.

The default registration form is registration.forms.RegistrationForm, so don't forget to check it or use it as parent class for your custom form.

Mark Mishyn
  • 3,921
  • 2
  • 28
  • 30
  • I did what you say with order but it gives error 'No module named my_accounts_app' . Did I missed something? – Hamlock B Jul 15 '16 at 08:49
  • Did you create applicaiton with this name? – Mark Mishyn Jul 15 '16 at 13:46
  • @HamlockB Create the app before adding it in the INSTALLED_APPS `python manage.py startapp my_accounts_app`. – kapilsdv Jul 16 '16 at 06:44
  • @MarkMishyn thanks for your answers but I am very new in django so I tried to solve problem for 2 days but I couldn't. What should I write inside of required_fields[] and when I tried to enter admin it gives 'Manager' object has no attribute 'get_by_natural_key' error. I took so many time of yours. Sorry for that – Hamlock B Jul 18 '16 at 08:22
  • REQUIRED_FIELDS is just list of all required User fields in addition to USERNAME_FIELD and password, you can leave it empty. I guess, that your User model is invalid now, could you show your User model? – Mark Mishyn Jul 18 '16 at 16:00