1
0
mirror of https://github.com/etesync/server synced 2024-11-25 10:18:12 +00:00

Implement item creation.

This commit is contained in:
Tom Hacohen 2020-02-26 16:07:55 +02:00
parent 4054a2f78c
commit 452a8f1e7e

View File

@ -118,6 +118,20 @@ class CollectionItemSerializer(serializers.ModelSerializer):
model = models.CollectionItem
fields = ('uid', 'content')
def create(self, validated_data):
"""Function that's called when this serializer creates an item"""
revision_data = validated_data.pop('content')
instance = self.__class__.Meta.model(**validated_data)
with transaction.atomic():
instance.save()
chunks = revision_data.pop('chunks')
revision = models.CollectionItemRevision.objects.create(**revision_data, item=instance)
revision.chunks.set(chunks)
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')