sunscrapers / djoser

REST implementation of Django authentication system.
MIT License
2.55k stars 458 forks source link

serializer for /users/me/ PATCH #813

Closed andypal333 closed 7 months ago

andypal333 commented 7 months ago

Based on the docs, we can make a PATCH request to /users/me/ by giving {{ User.FIELDS_TO_UPDATE }}. I have FIELDS_TO_UPDATE defined in my custom user model:

class CustomUser(AbstractBaseUser):
    email = models.EmailField(
        verbose_name="email address",
        max_length=255,
        unique=True,
    )
    first_name = models.CharField(max_length=150)
    last_name = models.CharField(max_length=150)
    # ...

    objects = CustomUserManager()

    USERNAME_FIELD = "email"
    REQUIRED_FIELDS = ["first_name", "last_name"]
    FIELDS_TO_UPDATE = ["first_name", "last_name"]

i have also set the serilizers like this:

DJOSER = {
    # ...
    "SERIALIZERS": {
        "current_user": "customauth.serializers.UserSerializer",
        "user": "customauth.serializers.UserSerializer",
        "user_update": "customauth.serializers.UserSerializer",
    },
class UserSerializer(BaseUserSerializer):
    class Meta(BaseUserSerializer.Meta):
        fields = ["id", "first_name", "last_name", "email"]

but serializer for PATCH request on /users/me/ is not working properly and not showing HTML form. But for PUT it shows HTML form with REQUIRED_FIELDS.

PATCH:

chrome_sOlUvbE6h4

PUT:

chrome_uwRiHdosLt

andypal333 commented 7 months ago

Okay this appears to be a problem with PATCH request in DRF. This problem has nothing to do with djoser.