one to one field update serialization issue

To perform the update, you have to override the update method in the serializer.

def update(self, instance, validated_data):
 = validated_data["profile"].get('profile_id',instance.profile.profile_id)
  instance.amt = validated_data.get('amt', instance.amt) 
  return instance

in your viewset

def update(self,request,pk=None):
   profile_id ="profile_id")
   profile = Profile.objects.get(profile_id = profile_id)
   ser = self.get_serializer_class()(instance=profile.cash_balance , data =

in your CashBalanceModel, pass a related_name

profile = models.OneToOneField(Profile, on_delete=models.CASCADE,db_column="profile_id" , related_name="cash_balance")

check docs:

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top