So, I'm fairly new to Django. Notwithstanding the fact that my code works after following the Django docs 'Customizing authentication in Django', I don't get how the self.model(...) in their example actually works, where it comes from and how it functions with 'self'.
This is the example found at the bottom of the docs.
from django.db import models
from django.contrib.auth.models import (
BaseUserManager, AbstractBaseUser
)
class MyUserManager(BaseUserManager):
def create_user(self, email, date_of_birth, password=None):
"""
Creates and saves a User with the given email, date of
birth and password.
"""
if not email:
raise ValueError('Users must have an email address')
-> user = self.model(
email=self.normalize_email(email),
date_of_birth=date_of_birth,
)
user.set_password(password)
user.save(using=self._db)
return user
...
add_to_class
class method ofModelBase
(which all models have as a meta-class) which callscontribute_to_class
ofBaseManager
(which all managers inherit from) which sets themodel
field. – Aoristic