mirror of
https://github.com/etesync/server
synced 2024-11-13 20:38:55 +00:00
Implement collection updating.
This commit is contained in:
parent
62a7496b66
commit
0fbc5c104c
@ -197,3 +197,19 @@ class CollectionSerializer(serializers.ModelSerializer):
|
||||
).save()
|
||||
|
||||
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…
Reference in New Issue
Block a user