<filename>app/apis/user_list/serializer.py
from rest_framework import serializers
from django.contrib.auth.models import User
from django.contrib.auth.hashers import make_password


class UserListSerializer(serializers.ModelSerializer):
    password = serializers.CharField(
        write_only=True,
        required=True,
    )

    class Meta:
        model = User
        fields = ['username', 'password']

    def create(self, validated_data):
        validated_data['password'] = <PASSWORD>(validated_data.get('password'))
        return super().create(validated_data)

    def update(self, instance, validated_data):
        validated_data['password'] = <PASSWORD>(validated_data.get('password'))
        return super().update(instance, validated_data)
