refactor: update AdventureSerializer to handle visits data more gracefully and remove visits from request body in AdventureCard
This commit is contained in:
@@ -116,7 +116,7 @@ class AdventureSerializer(CustomModelSerializer):
|
||||
return False
|
||||
|
||||
def create(self, validated_data):
|
||||
visits_data = validated_data.pop('visits', [])
|
||||
visits_data = validated_data.pop('visits', None)
|
||||
category_data = validated_data.pop('category', None)
|
||||
print(category_data)
|
||||
adventure = Adventure.objects.create(**validated_data)
|
||||
@@ -131,6 +131,7 @@ class AdventureSerializer(CustomModelSerializer):
|
||||
return adventure
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
has_visits = 'visits' in validated_data
|
||||
visits_data = validated_data.pop('visits', [])
|
||||
category_data = validated_data.pop('category', None)
|
||||
|
||||
@@ -142,6 +143,7 @@ class AdventureSerializer(CustomModelSerializer):
|
||||
instance.category = category
|
||||
instance.save()
|
||||
|
||||
if has_visits:
|
||||
current_visits = instance.visits.all()
|
||||
current_visit_ids = set(current_visits.values_list('id', flat=True))
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ collection: null, visits: adventure.visits })
|
||||
body: JSON.stringify({ collection: null })
|
||||
});
|
||||
if (res.ok) {
|
||||
addToast('info', `${$t('adventures.collection_remove_success')}`);
|
||||
@@ -97,7 +97,7 @@
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ collection: collectionId, visits: adventure.visits })
|
||||
body: JSON.stringify({ collection: collectionId })
|
||||
});
|
||||
if (res.ok) {
|
||||
console.log('Adventure linked to collection');
|
||||
|
||||
Reference in New Issue
Block a user