假设我有一个Vehicle模型给定的资源:
class Vehicle(models):
doors = models.Integerfield
brand = models.CharField
从不同的主机,我发送PUT请求以使用requests包更新其中一个属性:
requests.put(remote_host + "/" + vehicle_id, data={"brand":"New Brand"})
注意:门没有更新。
现在在遥控器上,我想更新正在发送的任何属性。这将发生在views.py资源Vehicle中:
def update(self, request):
vehicle_to_update = Vehicle.objects.get(pk=self.request.data["id"])
# How do I know here, that it is only "brand" that is being updated?
# Do I need to check for every possible property and see if a value was provided?
vehicle_to_update.brand = self.request.data["brand"]
vehicle_to_update.save()