djoser icon indicating copy to clipboard operation
djoser copied to clipboard

users/me(PATCH) : Is this working?

Open imuradevelopment opened this issue 3 years ago • 3 comments

First of all, what does "User.FIELDS_TO_UPDATE" as described in the documentation linked below indicate? Does it indicate a field other than "REQUIRED_FIELDS" or "USERNAME_FIELD"? If this idea is correct, then the next question makes sense.

User.FIELDS_TO_UPDATE


Secondly, I am using djoser's with a custom user model below. But I can't update the "description" using the "users/me(PATHCH)" endpoint.

class User(AbstractBaseUser, PermissionsMixin):
    """
    管理者に準拠したパーミッションを持つ、完全に機能するUserモデルを実装する抽象ベースクラスです。

    ユーザー名とパスワードは必須です。その他の項目は任意です。
    """
    id = models.UUIDField(
        default=uuid_lib.uuid4,
        primary_key=True,
        editable=False
        )
    user_id_validator = ASCIIUsernameValidator()
    user_id = models.CharField(
        _('user_id'),
        max_length=30,
        unique=True,
        help_text=_('半角アルファベット、半角数字、@/./+/-/_ で150文字以下にしてください。'),
        validators=[user_id_validator],
        error_messages={
            'unique': _("同じユーザーIDが既に登録済みです。"),
        },
    )
    username_validator = UnicodeUsernameValidator()
    username = models.CharField(
        _('username'),
        max_length=150,
        unique=True,
        help_text=_('半角アルファベット、半角数字、@/./+/-/_ で150文字以下にしてください。'),
        validators=[username_validator],
        error_messages={
            'unique': _("A user with that username already exists."),
        },
    )
    description = models.CharField(
        _('description'),
        max_length=30,
        blank=True, null=True
    )
    email = models.EmailField(_('email address'), unique=True)
    is_staff = models.BooleanField(
        _('staff status'),
        default=False,
        help_text=_('Designates whether the user can log into this admin site.'),
    )
    is_active = models.BooleanField(
        _('active'),
        default=True,
        help_text=_(
            'Designates whether this user should be treated as active. '
            'Unselect this instead of deleting accounts.'
        ),
    )
    date_joined = models.DateTimeField(_('date joined'), default=timezone.now)

    objects = UserManager()

    EMAIL_FIELD = 'email'
    REQUIRED_FIELDS = ['email', 'user_id']
    USERNAME_FIELD = 'username'

    class Meta:
        verbose_name = _('user')
        verbose_name_plural = _('users')
        # abstract = True

The result of running the "users/me(PATHCH)" endpoint is shown below.

PATCH http://127.0.0.1:8000/api/v1/users/me/
Authorization: token {{token}}
content-type: application/json

{
  "description":"patchTest"
}

The http request was successful.

HTTP/1.1 200 OK
Date: Sat, 10 Jul 2021 12:47:29 GMT
Server: WSGIServer/0.2 CPython/3.9.4
Content-Type: application/json
Vary: Accept, Origin
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
X-Frame-Options: DENY
Content-Length: 77
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin

{
  "email": "[email protected]",
  "user_id": "user01",
  "username": "ユーザー01"
}

imuradevelopment avatar Jul 10 '21 13:07 imuradevelopment

any news on this problem? I'm facing the exact same problem

sdezza avatar Jan 05 '22 21:01 sdezza

AFAIK you will need to implement a custom serializer class for your user in order to update the information. Heres an example serializer

James-Burgess avatar Jan 26 '22 09:01 James-Burgess

when i changed /users/me/ to /user/me/ then it works But i dont know how.....

anurag629 avatar Feb 28 '22 18:02 anurag629