def _update_trip(self, data): instance = Trip.objects.get(id=data.get('id')) serializer = TripSerializer(data=data) serializer.is_valid(raise_exception=True) return serializer.update(instance, serializer.validated_data)
def _update_trip(self, data): # Retrieve the Trip obj by ID instance = Trip.objects.get(id=data.get('id')) # Serialize the Trip data with update serializer = TripSerializer(data=data) # Ensure the serialized data is valid according to the model fields serializer.is_valid(raise_exception=True) # Use built-in update() passing in the Trip obj (instance) and the serializer data return serializer.update(instance, serializer.validated_data)
def _update_trip(self, content): instance = Trip.objects.get(id=content.get('id')) serializer = TripSerializer(data=content) serializer.is_valid(raise_exception=True) trip = serializer.update(instance, serializer.validated_data) return trip