Skip to content Skip to sidebar Skip to footer

Trying To Override Djoser Serializer Getting AttributeError: Got AttributeError When Attempting To Get A Value For Field Error

I am new to djoser I am user to authenicate a user. I then wanted patient information to be displayed when user/me is accessed but i overrode it to also show patient details as wel

Solution 1:

I'm not sure but it seems that you're passing a User object to the Patient serializer, which doesn't have those fields.

try:

    def create(self, serializer):
        patinet_info = PatientInfo.objects.filter(user_profile=self.request.user)
        serializer = self.get_serializer(patinet_info, many = True) # This sets the user profile to the current user from the serializer passed in 
        serializer.is_valid(raise_exceptions=True)
        self.perform_create(serializer)
        return Response(serializer.data)

now, the thing is that user_profile is a Foreign key, so they can be multiple users for patients according to your model. this is why I added many= True you should also notice I'm overriding the create and not the perform create method. this is a more suitable place for that.


Post a Comment for "Trying To Override Djoser Serializer Getting AttributeError: Got AttributeError When Attempting To Get A Value For Field Error"