1

Within the Django file /django/contrib/auth/models.py , in the class class UserManager(BaseUserManager): , have inserted the prints as seen below .

Now creating new users - nothing gets printed in the terminal . My Question - Why wont the email and username print into the terminal ? Is the _create_user method not being used , when creating a new user?

class UserManager(BaseUserManager):
    use_in_migrations = True

    def _create_user(self, username, email, password, **extra_fields): 
        """
        Create and save a user with the given username, email, and password.
        """
        print("--PlaceHolder----") # Doesnt Print in Terminal 
        if not username:
            raise ValueError('The given username must be set')
        email = self.normalize_email(email)
        print(email) # Doesnt Print in Terminal 
        username = self.model.normalize_username(username)
        print(username) # Doesnt Print in Terminal 

I understand that the class class UserManager(BaseUserManager) is being called with the line of code objects = UserManager() within the class class AbstractUser(AbstractBaseUser, PermissionsMixin): , in the same file .

This question is a follow-up to my earlier question here - Django - UserModel - How to create Custom Text Field within the django/contrib/auth/forms.py

*EDIT -1- * Also - i do understand that the create_user method internally calls the _create_user method .

Rohit Dhankar
  • 1,574
  • 18
  • 25
  • How are you creating a new user? – heemayl Nov 08 '19 at 16:29
  • @heemayl - Am using the Registration Form - ```class RegistrationView(FormView):``` , from the file ```/site-packages/registration/views.py``` . – Rohit Dhankar Nov 08 '19 at 16:32
  • My intention is to understand the flow and then be able to modify the default User Model , i have also read through most tests in the Django Git repo here , i do understand that the ```create_user``` method internally calls the ```_create_user``` method . Django tests that i read through are here - https://github.com/django/django/tree/b9cf764be62e77b4777b3a75ec256f6209a57671/tests/auth_tests/models – Rohit Dhankar Nov 08 '19 at 16:40
  • There are many ways to create a User instance, and using `.create_user` is not mandatory. You need to see how it's being created in this very case. – heemayl Nov 08 '19 at 17:07

0 Answers0