Closed andypal333 closed 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:
PATCH
/users/me/
{{ User.FIELDS_TO_UPDATE }}
FIELDS_TO_UPDATE
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:
serilizers
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.
HTML form
PUT
REQUIRED_FIELDS
PATCH:
PUT:
settings.py
Okay this appears to be a problem with PATCH request in DRF. This problem has nothing to do with djoser.
Based on the docs, we can make a
PATCH
request to/users/me/
by giving{{ User.FIELDS_TO_UPDATE }}
. I haveFIELDS_TO_UPDATE
defined in my custom user model:i have also set the
serilizers
like this:but serializer for
PATCH
request on/users/me/
is not working properly and not showingHTML form
. But forPUT
it showsHTML form
withREQUIRED_FIELDS
.PATCH
:PUT
:settings.py
to enableHTML form
in/users/me/
when usingPATCH
?FIELDS_TO_UPDATE
?