[Django]-Django Rest Framework update() with kwargs from validated_data

10👍

It’s not a one-liner but short enough (extracted from the drf sources):

def update(self, instance, validated_data):
    for attr, value in validated_data.items():
        setattr(instance, attr, value)
    instance.save()
    return instance

Leave a comment