Model inherited from AbstractUser doesn't hash password field
You don't have to actually define your own function. You just need to use register it with the UserAdmin
class from django.contrib.auth.admin
and it works out of the box.
Explicitly, in your admin.py file make sure you have the following:
from django.contrib.auth.admin import UserAdmin
admin.site.register(CustomUserModel, UserAdmin)
If you have additional custom fields on your model, the above way of registering will make them not shown in the admin. In this case, you can make it work by making your custom Admin class inherit from the UserAdmin
class, like the following:
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
@admin.register(CustomUserModel)
class CustomUserModelAdmin(UserAdmin):
...
You need to define a function to hash that password. I think you directly save it to database.
class MyForm(forms.ModelForm):
............
def save(self, commit=True):
# Save the provided password in hashed format
user = super(MyForm, self).save(commit=False)
user.set_password(self.cleaned_data["password"])
if commit:
user.save()
return user