1

I don't have idea to put extra field in default admin user table/ model in django 3.0.3 version . Please give some idea to make extra field like user_roll, user_id, designation etc.

1 Answers1

1

For that you have to extend AbstractUser as below and add extra field as per your requirements...

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


class User(AbstractUser):
    # Add your extra field here
    my_custom_field = models.CharField(max_length=2)

In this example my_custom_field would be your custom field . You have a number of options, BooleanField (true/fales), IntField ... etc) and you can add as many (within reason, as you like).

And suppose this User model is in app named app_1 then you have to set AUTH_USER_MODEL in settings.py as below...

settings.py

AUTH_USER_MODEL = "app_1.User"

Run makemigrations and migrate commmand because we changed in model.

AppHandwerker
  • 1,758
  • 12
  • 22
MK Patel
  • 1,354
  • 1
  • 7
  • 18
  • 1
    Technically, while I get what you're saying here you haven't actually shown him how to add a Field probably want give him an example – AppHandwerker Mar 18 '20 at 10:36