Skip to content

Instantly share code, notes, and snippets.

@brunomichetti
Created July 1, 2022 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunomichetti/d67af1a9225c41a563f5a2f2af38ca7b to your computer and use it in GitHub Desktop.
Save brunomichetti/d67af1a9225c41a563f5a2f2af38ca7b to your computer and use it in GitHub Desktop.
# model.py in the Django app called users
from django.db import models
from django.contrib.auth.models import AbstractUser
# class to define choices
class Category(models.TextChoices):
GUEST = 'G', 'Guest user'
COMMON_USER = 'C', 'Common user'
ADMIN = 'A', 'Admin user'
# user model that inherits from AbstractUser
# there is no need to define a username field
# because is defined in the parent class
class User(AbstractUser):
phone_number = models.CharField(max_length=50, blank=True, null=True)
category = models.CharField(
max_length=1,
choices=Category.choices,
default='G',
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment