2

How to add a field in Django User Model?

 2 years ago
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?

advertisements

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

I tried to add search fields in Django using python. Followings are the codes that I have used. # admin.py file from django.db import models from blog.models import Blog from django.contrib import admin admin.site.register(Blog) class Blog(models.Mod

How to add additional fields to the user in django-cms? (in the django admin panel)

I would like to add some extra fields to user in django-cms (in django admin panel). How to do this in the simplest way? Need to add two fields user bio and image. And can i use this in frontend to show a page with all the user info?From the django d

Add db_index to the Django User model?

I have a custom user model that takes in the following fields: class MyUser(AbstractBaseUser, PermissionsMixin): username = models.CharField(max_length=60, unique=True) email = models.EmailField(max_length=120, unique=True) full_name = models.CharFie

how to add the field "subject" with the model "book" to store in the database

i am a newbie to rails i am stuck at a point i have related models Book and Subject where Book related_to:Subject and Subject has_many:books now what can i do to store subject field while saving the book instance book model file :book.rb class Book <

Extending the Django user model with django-allauth

I'm using django-allauth and I want to be able to add new field to my User model. What's the best way to do this as of you ?I use userena. But I am sure that it will look almost the same ;) class UserProfile(UserenaBaseProfile): user = models.OneToOn

How do I change the default django user template to meet my needs?

The default Django's User model has some fields, and validation rules, that I don't really need. I want to make registration as simple as possible, i.e. require either email or username, or phone number - all those being unique, hence good as user id

How to extend the Django user model with two different profiles?

Is it possible to create two different profiles and have them both extend Django User Model. I am trying to create a student profile and a teacher profile, how should I go about doing this? My student profile has attributes such as courses taken, but

Entity Framework 4 (using EDMX), how to add a field in to model that DB does not have the field actually

I need to add a field into model that Database does not have the field actually. Because, firstly I tried to add the field into Entity class only. public partial class Weborder { (Auto Generated) public int orderno {get; set;} . . . (Add Manually) pu

Extending the Django user model using Django-mptt

I have a hierarchical structure in the sense that there can be a Company and a User, where a company can be nested within another company while users can be independent or belong to a company. Is there any documentation on how to use the django user

customization request.user with a proxy template that extends Django user model

class MyUser(User): class Meta: proxy = True def do_something: ... With the above, I extend the behavior of the Django User Model using the proxy model technique. I was hoping that I could somehow customize request.user, so that MyUser instance, inst

Sentry 2 and Laravel 4 adding fields to the user model

Im trying to add fields to the Users model that is based around Sentry 2 for Laravel 4. I want to do it properly with migrations. Is there a way to simply add to the sentry 2 migrations? or should i simply make my own migrations and add the required

Is it better to extend or replace the Django User model?

I need to have some additional fields in my User model and i don't know which is the best path to follow. My first idea is to create a new model with my fields, as explained here, but i want it to be created along the User model and it will be needed

How to get the field value of a model from another model in Odoo?

I'm having some trouble to understand how to get field values from another model. I added a custom field in res.partner module by making a custom module: class custom_partner_fields(osv.osv): _inherit = 'res.partner' _columns = { 'RTN': fields.char('

Django - Return the full name of the profile template that has a relationship with the Django user model in another template

I created Book, Book_stat a Profile model which has relation with Django User Model, i am trying to display Book title and full_name from Profile as default str return string from Book_stat models.py from django.db import models from django.contrib.a

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK