Hi all,
I am following this tutorial (http://musings.tinbrain.net/blog/2014/sep/21/registration-django-easy-way/) to create a user registration model in Django.
I understand that the class UserManager is overwriting the default User model. However, I do not understand this particular part.
The official Django Documentation doesn't explain what this means - It merely shows the full code.
https://docs.djangoproject.com/en/1.7/topics/auth/customizing/
Need some clarification as to what's going on here. What is self.model in this example and what does it do?
def create_user(self, email, password, **kwargs):
user = self.model(email=self.normalize_email(email), is_active=True, **kwargs)
user.set_password(password)
user.save(using=self._db)
return user
class UserManager(BaseUserManager):
def create_user(self, email, password, **kwargs):
user = self.model(email=self.normalize_email(email), is_active=True, **kwargs)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, password, **kwargs):
user = self.model(email=email, is_staff=True, is_superuser=True, is_active=True, **kwargs)
user.set_password(password)
user.save(using=self._db)
return user
Hi all,
I am following this tutorial (http://musings.tinbrain.net/blog/2014/sep/21/registration-django-easy-way/) to create a user registration model in Django.
I understand that the class UserManager is overwriting the default User model. However, I do not understand this particular part.
The official Django Documentation doesn't explain what this means - It merely shows the full code.
https://docs.djangoproject.com/en/1.7/topics/auth/customizing/
Need some clarification as to what's going on here. What is self.model in this example and what does it do?
def create_user(self, email, password, **kwargs):
user = self.model(email=self.normalize_email(email), is_active=True, **kwargs)
user.set_password(password)
user.save(using=self._db)
return user