How to add a field in Django User Model?
source link: https://www.codesd.com/item/how-to-add-a-field-in-django-user-model.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to add a field in Django User Model?
I have three different types of users in my project. The three models have OneToOneField with the User model.
In many cases, I want to figure out which of the three type the user is. Is there a quick way to do that?
I'm thinking to add a field in User model but not sure how that can be done.
To extend the User
model with your extra fields, you can use AbstractUser
model. This will provide you with all the User
fields like username
, email
and etc. Then, add all the extra fields in MyUser
model.
You need to do something like:
models.py
from django.contrib.auth.models import AbstractUser
class MyUser(AbstractUser):
my_extra_field = .. # your extra field
This will provide all the User
fields along with the extra field named my_extra_field
in MyUser
model.
Related Articles
How to add search fields in Django
How to add additional fields to the user in django-cms? (in the django admin panel)
Add db_index to the Django User model?
how to add the field "subject" with the model "book" to store in the database
Extending the Django user model with django-allauth
How do I change the default django user template to meet my needs?
How to extend the Django user model with two different profiles?
Entity Framework 4 (using EDMX), how to add a field in to model that DB does not have the field actually
Extending the Django user model using Django-mptt
customization request.user with a proxy template that extends Django user model
Sentry 2 and Laravel 4 adding fields to the user model
Is it better to extend or replace the Django User model?
How to get the field value of a model from another model in Odoo?
Django - Return the full name of the profile template that has a relationship with the Django user model in another template
Recommend
-
73
Remove django form field validation errors manuallyRemove django form field validation errors manually Tue 06 December 2011Original post at Makina Corpus Sometimes I look fo...
-
4
Building a Read Only Field in Django Sun, Dec 28, 2008One commonly requested feature in Django is to have a field on a form(or in the admin), that is read only. Such a thing is going may be a Django 1.1 feature for the admin,...
-
6
In the previous post, I discussed how you can create a custom User model in Django but what if you don't want to create a custom one. In that case, Yo...
-
13
Cloning Django models or adding a differentiator field in the second model? advertisements I have to store live streaming 'test' data and trai...
-
8
Django week_day Field lookup Hi, I'm Ana. I'm a software developer. I mostly do Python....
-
11
Poulami Das June 16, 2022 5 minute read ...
-
1
User model with email as the identifier in Django Django • Aug 6, 2022...
-
4
Creating a User Profile model in Django to hold additional user info Django • Mar 4, 2023 Creating a new user in a Django project...
-
2
django field constraint ...
-
4
xiaosan yu June 29, 2023 2 minute read ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK