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
This is the entire code.
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
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3bd8dc94-0a6f-4363-98ca-9baf7b504e97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment