Django 2.1 and Python 3 User Authentication System — #2(Using the AbstractUser Class)

Abedy Ng'ang'a
2 min readJan 5, 2019

Hey there. Before we begin, it is important that you read my previous article on the default Django User model as it contains all the necessary configurations to our project as well as a detailed explanation of the user model. If you’re new to Django on the other hand, you might want to read this first. With that, let’s get started.

So on this article we’re not exactly going to be doing a lot. As a matter of fact we’re only going to be changing our ‘models.py’ file in our users app.

But wait a minute, why would we want to use another User model? Well, at times you want more details from the user other than their username and password as they create an account. For instance their first and last names, their age, et cetera. So what the AbstractUser class does is, it provides you with the username and passwords, but on top of that you get to define your own extra model fields.

So in our case, we’ll add two extra fields, a ‘select’ field (Django choice field) and a Date field. And this is what our ‘models.py’ file will look like.

From that we’ll do the normal

python manage.py makemigrations

and then

python manage.py migrate

With that we’ll then need to register our model in the admin.py file by adding the following

And with that we’re simply done. Just run your server and everything should work just fine.

Next we’ll be tackling the AbstractBaseUser class approach. I hope you enjoyed the read. Till then, have a nice time.

--

--