Implement collection updating.

master
Tom Hacohen 5 years ago
parent 62a7496b66
commit 0fbc5c104c

@ -197,3 +197,19 @@ class CollectionSerializer(serializers.ModelSerializer):
).save() ).save()
return instance return instance
def update(self, instance, validated_data):
"""Function that's called when this serializer is meant to update an item"""
revision_data = validated_data.pop('content')
with transaction.atomic():
main_item = instance.mainItem
# We don't have to use select_for_update here because the unique constraint on current guards against
# the race condition. But it's a good idea because it'll lock and wait rather than fail.
current_revision = main_item.revisions.filter(current=True).select_for_update().first()
current_revision.current = None
current_revision.save()
process_revisions_for_item(main_item, revision_data)
return instance

Loading…
Cancel
Save