Reputation: 19
There are some Boolean fields in Django's User
Model, for example is_staff
, is_anonymous
etc.
How can I create my own Boolean field, for example is_student
and add it into Django's User
model?
Upvotes: 0
Views: 473
Reputation: 3457
You can create custom user model that is derived from AbstractUser
.
from django.contrib.auth.models import AbstractUser
class Student(AbstractUser):
is_student = models.BooleanField(default=False)
And in settings.py, you need to set this user model as the AuthUser model.
For example, if the Student
model is defined in the schools
app, then
AUTH_USER_MODEL = 'schools.Student'
Upvotes: 2