0

Hi im new to django and python, i want to make API to add user and it worked but when i try login with it but the result is i cant login, seems like it must hash password for system can read the user, and i try to hash my password in model.

heres my model :

from django.contrib.auth.hashers import make_password

class MyUser(AbstractUser):
pass
password = models.CharField(max_length=128, null=False)

def save(self, *args, **kwargs):
    self.password = make_password(self.password)

but its make id become null heres the screenshot of result when i use make_passwod and not:

screenshot when make_password not added

screenshot when make_password added

im following this tutorial with a bit modification heres the link django-rest-framework-create-api

cause the id null the data not saved to database. So the question how to add the id ? why the id become null when i add make_password ? or maybe i am missing something ?

thank you in advance

Raka Akaa
  • 3
  • 6
  • I would recommend to has your password in view or serializer/forms, not in your `save()` method of Model – JPG Feb 24 '23 at 04:02
  • hi thankyou @JPG for answere the question. can you share it how to do it ?, cause i have no clue how to add hash in serializer – Raka Akaa Feb 24 '23 at 04:12
  • @JPG thank you for the clue, im following this https://stackoverflow.com/questions/41332528/how-to-hash-django-user-password-in-django-rest-framework and and it worked !!! – Raka Akaa Feb 24 '23 at 04:24

0 Answers0