If I'm understanding this correctly, you had to pass a username in order to create a superuser, but I want to delete username alltogether and only use email.
@JorgeRamirez01 Жыл бұрын
Thanks for the tutorial! What happens if you want to implement this approach on an existing project? I see that in this video you deleted the database, but what happens if you can't do that? Is there another way? Or recreating the database is the only way to do it? Thanks!
@Pyplane Жыл бұрын
I did it because it is the easiest way. If you change the user model on an existing project you most likely will get errors. If you decide to do it be sure to backup your data. Good luck!
@faizannazir5596 Жыл бұрын
User._meta.get_field('username')._unique = False User._meta.get_field('email')._unique = True User.USERNAME_FIELD = 'email' User.REQUIRED_FIELDS.remove('email') User.REQUIRED_FIELDS.append('username') class AppUser(User): department = models.CharField(max_length=50) picture = models.ImageField() db_picture = models.BinaryField(verbose_name="Image_db",editable=True,null=True,blank=True) date_of_birth = models.DateField(validators=[validate_at_least_18_years_old]) joining_date = models.DateField(validators=[validate_not_after_today]) customBackend from django.contrib.auth.backends import BaseBackend from django.contrib.auth.models import User class EmailBackend(BaseBackend): def authenticate(self, request, email=None, password=None, **kwargs): try: user = User.objects.get(email=email) if user.check_password(password): return user except User.DoesNotExist: return None def get_user(self, user_id): try: return User.objects.get(pk=user_id) except User.DoesNotExist: return None # change to custom backend in settings AUTHENTICATION_BACKENDS = [ 'myapp.backends.EmailBackend', 'django.contrib.auth.backends.ModelBackend', ]
@UserHuge7 ай бұрын
You should write a custom migration to move your users from the old model/table to the new one. Ideally test it aside on a copy of your prod db.
@bastianvalero4612 Жыл бұрын
Hi! If you were to create a project of an eCommerce and separate the Normal users from sellers would you do it with abstractbaseuser or you would create a usermanager(BaseUserManager) and then create the normaluser(abstractuser) and seller(abstractuser)? cuz both would have different GUIs and functionalities, Last question, If the website was planned to be scaled in the future and wanted to have jwt auth or oAuth 2.0 would the path be similar or how it would be? Also, do you have a video on this topic? If so I'd apprecciate the link, and sorry for so many questions, but I recently started to read this same docummentation and was wondering these things. Thank you