Django Custom User Model | Extend User Model Fields | AbstractUser | Django ORM Mastery

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ก.ย. 2024
  • This tutorial teaches how to extend the Django User Model by inheriting and developing a new User table. The Django 4. x ORM course provides learners with a complete overview of the Django Framework ORM (Object-relational mapping) through applied learning. In this course, you’ll learn about Django ORM and SQL features. By better understanding the features of the Django ORM, you will learn how to interact with databases from within a Django project, as you would with SQL. You will also learn how to administrate tables and perform common Create, Return, Update and Delete (CRUD) operations through the Django ORM.
    Udemy Course Link: Django 4.x ORM Mastery
    ===================
    www.udemy.com/...
    TH-cam Playlist
    ===================
    • DJ101 | Django Databas...
    GitHub Code Repository - Extend User Model
    ===================

ความคิดเห็น • 27

  • @KingdomIncreasingMiracles
    @KingdomIncreasingMiracles ปีที่แล้ว +3

    Hi Zander, I wanted to say that you have explained the User information better here than anywhere else I have studied. You are an excellent teacher. I love how detailed you are. I am very detailed in how I do anything so this is refreshing. I was confused on this topic regarding User and not sure how to proceed in my K.I.M. project. I certainly do not want my db setup wrong. Thank you very much Zander. You really helped me tremendously with the User tutorials.

    • @veryacademy
      @veryacademy  ปีที่แล้ว

      Nice to hear from you, hope you are getting on well with your project!

    • @KingdomIncreasingMiracles
      @KingdomIncreasingMiracles ปีที่แล้ว +1

      @@veryacademy thank you for your support of my mission. It is awesome to hear back from you too! 😊I plan to deploy my new site this week to replace the old one. I still have lots to add but I am adding the functionality I need in detail as I will need it for my work. I didn't want to rush this and have a weak foundation. One thing I have learned since we last spoke, when I started my new website, is that I learn and understand the code best from your teachings since you explain exactly what is going on with the code and the goals of the code used! Thank you truly. Have a great week!

  • @diegoc.1212
    @diegoc.1212 ปีที่แล้ว

    Thank you, you won't imagine how long I have been reading trying to understand this :)

  • @RahulGupta-pw5ei
    @RahulGupta-pw5ei ปีที่แล้ว +1

    Great sir i love ur teaching style

  • @waseem1162
    @waseem1162 2 ปีที่แล้ว

    Appreciate your hard work 👍

  • @thezeeshann
    @thezeeshann ปีที่แล้ว +1

    Thanks man 🙏

  • @omarbd5659
    @omarbd5659 ปีที่แล้ว

    fantastic content, thank you very much for your awesome effort

  • @shamimanowar1726
    @shamimanowar1726 2 ปีที่แล้ว

    Great sir❣️

  • @joy_sam_raj
    @joy_sam_raj 2 ปีที่แล้ว

    Thank you very Much

  • @mousaalzahrani1873
    @mousaalzahrani1873 5 หลายเดือนก่อน

    Thanks for wonderful video .
    but when click on [add user] all additional fields will disappear it just appear when you trying to [edit] the information for users !

  • @rangabharath4253
    @rangabharath4253 2 ปีที่แล้ว

    awesome

  • @raphaelhunold6812
    @raphaelhunold6812 ปีที่แล้ว +1

    Really enjoy your video. I was wondering why your custom AbstractUser (NewUser) is shown as "Users" in the left panel in the Admin. How can you customize the label of you model name in in the admin ?

    • @veryacademy
      @veryacademy  ปีที่แล้ว

      Have a look at model meta verbose_name

  • @rishabhsharma667
    @rishabhsharma667 2 ปีที่แล้ว

    Sir please make videos on microservices.

  • @hasibullahwardak4514
    @hasibullahwardak4514 8 หลายเดือนก่อน

    I followed up
    I created superuser and ordinary user accounts.
    I can login with super user account
    but in ordinary user account it tells me:
    wrong username or password
    while I created many ordinary accounts from admin- superuser
    can anyone help.

  • @enzolarosa4148
    @enzolarosa4148 2 ปีที่แล้ว

    Hi thanks a lot for you videos they are very helpful, can you please insert the link to the GitHub Code Repository, thanks

  • @AbdullahKhan-ft5bj
    @AbdullahKhan-ft5bj ปีที่แล้ว +1

    hi guys can anyone help me I am unable to refer to the extra_fields using request.user.extra_fields in views, how can I achieve this

    • @veryacademy
      @veryacademy  ปีที่แล้ว

      In Django, the request.user object represents the current user that is authenticated. By default, Django's built-in authentication system provides a User object with certain predefined fields like username, email, etc. If you need additional fields for your users, you have a few options to achieve this:
      Extending the User Model: You can extend the default User model by creating a custom user model that includes additional fields. This allows you to store extra information for your users. Here's an example of how you can do this:
      # models.py
      from django.contrib.auth.models import AbstractUser
      from django.db import models
      class CustomUser(AbstractUser):
      # Add your extra fields here
      extra_fields = models.CharField(max_length=100, blank=True)
      Remember to update your settings.py to use your custom user model:
      # settings.py
      AUTH_USER_MODEL = 'yourapp.CustomUser'
      Profile Model: Another common approach is to create a separate UserProfile model associated with the default User model using a one-to-one relationship. This allows you to keep the default User model clean while adding additional fields in the profile model:
      # models.py
      from django.contrib.auth.models import User
      from django.db import models
      class UserProfile(models.Model):
      user = models.OneToOneField(User, on_delete=models.CASCADE)
      extra_fields = models.CharField(max_length=100, blank=True)
      User Model Extension with AbstractBaseUser: For more flexibility and customization, you can create a custom user model by inheriting from AbstractBaseUser and create your own user model with the desired fields.
      After creating or extending your user model, don't forget to run makemigrations and migrate to apply the changes to your database.
      Once you have extended the user model or created a separate profile model, you should be able to access the extra_fields attribute through the request.user object in your views. For example:
      # views.py
      from django.contrib.auth.decorators import login_required
      from django.shortcuts import render
      @login_required
      def my_view(request):
      # Access the extra_fields attribute of the authenticated user
      extra_fields_value = request.user.extra_fields
      # Your view logic here
      ...
      return render(request, 'template.html', context)
      Remember to ensure that the user is authenticated before accessing the extra_fields attribute by using the @login_required decorator or checking request.user.is_authenticated in your view.

    • @AbdullahKhan-ft5bj
      @AbdullahKhan-ft5bj ปีที่แล้ว

      @@veryacademy thank for the reply i followed the same steps as you mentioned but it still shows extra_fields is not a defined fields in class User

  • @georgesmith3022
    @georgesmith3022 ปีที่แล้ว +1

    you didn't touch the most common requirement of creating a custom user. this is to change authentication with email instead of username

    • @veryacademy
      @veryacademy  ปีที่แล้ว +1

      Thanks George, there are a few more tutorials to go yet with this.

  • @joy_sam_raj
    @joy_sam_raj 2 ปีที่แล้ว

    Please update this in a Github Repo

  • @user-zw8vo8se2d
    @user-zw8vo8se2d ปีที่แล้ว

    thanks

  • @waseem1162
    @waseem1162 2 ปีที่แล้ว

    Appreciate your hard work 👍