Django Registration

What is Django Registration?

Django Registration is the process of user registration in Django’s authenticate and authorized admin panel. Till now, we are using python manage.py createsuperuser command to get login credentials. But now, we will discuss about how to get registered on that system. Furthermore, we will discuss about login system.

This tutorial basically teaches you how to register on Djnago’s authentication and authorization system. Basically it avoids to create superuser using command prompt, i.e. using GUI(templates) instead.

Django Registration
Django Registration

User Model

To register on Django site, first of all you need to understand about User Model. Now we will discuss about how to use Django’s built in tools to create user authorization models.Here are some important points:

  • You can see in the admin panel, there are “users”, Let’s learn how to use this feature.
  • There were two things(users and groups) in admin, we will use “users”.
  • The user object has a few key features:
      1. Username
      2. Email
      3. Password
      4. First Name
      5. Last Name
  • There are also some other attributes for the user object, such as:
    1. is_active
    2. is_staff
    3. is_superuser
    4. Groups
    5. Date joined etc
  • Moreover, You can also add more attributes to user such as images, links etc.
  • You can create User Model in your application’s models.py file by creating another class.
  • This class has a relationship to the built in User class.

Example

Now we will create a model class using built in User model.Here is my project’s directory:

Django Registration
Django Registration

Step 1: Create model using built in User model

  • Import User model from djnago > contrib > auth directrory

firstproject > myapp > models.py

from django.db import models
from django.contrib.auth.models import User

class registerModel(models.Model):
    user = models.OneToOneField(User, on_delete = models.CASCADE)

    def __str__(self):
        return self.user.username

What is OneToOneField ?

Here, One to one field means that, child table registerationModel has an one to one relationship with parent model User.  One to one relationship means username field of User(parent) table relates to one and only one time to username field of child table.

 

  • Add model to admin.py file

firstproject > myapp > admin.py

from django.contrib import admin
from .models import registerModel

admin.site.register(registerModel)
  • Apply Migrations using:
      1. python manage.py makemigrations
      2. python manage.py migrate
  • And check the output in admin model.

Output

-You can see below the model we created:

Django Registration
Django Registration

-You can see below as there is only single superuser in admin i.e. showing in dropdown menu:

Django Registration
Django Registration

Download source code

Download project on Github
Download project on Github 

So it is all about creating model from built in User Model. In our further tutorials we will discuss about creating model forms and complete django registration. I hope you guys enjoyed the post. Thanks!!!

14 thoughts on “Django Registration

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Oh my goodness! an incredible article dude. Thanks Nevertheless I’m experiencing problem with ur rss . Don’t know why Unable to subscribe to it. Is there anybody getting similar rss problem? Anyone who knows kindly respond. Thnkx

  2. What’s Happening i’m new to this, I stumbled upon this I’ve found It positively useful and it has aided me out loads. I hope to contribute & assist other users like its helped me. Good job.

  3. There are definitely a lot of details like that to take into consideration. That could be a nice point to bring up. I supply the thoughts above as common inspiration however clearly there are questions just like the one you deliver up where an important thing shall be working in sincere good faith. I don?t know if finest practices have emerged round issues like that, but I am positive that your job is clearly identified as a good game. Both boys and girls feel the influence of only a second’s pleasure, for the rest of their lives.

  4. Woah! I’m really loving the template/theme of this blog. It’s simple, yet effective. A lot of times it’s tough to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a excellent job with this. Additionally, the blog loads super fast for me on Safari. Superb Blog!

  5. Pretty section of content. I just stumbled upon your weblog and in accession capital to assert that I acquire in fact enjoyed account your blog posts. Anyway I?ll be subscribing to your augment and even I achievement you access consistently rapidly.

  6. Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something. I think that you can do with some pics to drive the message home a bit, but other than that, this is magnificent blog. An excellent read. I’ll certainly be back.

  7. I precisely wished to say thanks once more. I am not sure what I might have created without these tips documented by you over that subject matter. Previously it was a real frightening matter for me personally, nevertheless viewing a new specialized way you handled the issue made me to cry for happiness. Now i am happier for the work and then expect you find out what a great job you have been doing training the rest via a site. I am sure you’ve never come across all of us.

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.