1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-19 12:59:36 +02:00

refactor: update AdventureSerializer to handle visits data more gracefully and remove visits from request body in AdventureCard

This commit is contained in:
Sean Morley 2025-01-03 09:53:23 -05:00
parent 6651557738
commit 57e367d112
2 changed files with 21 additions and 19 deletions

View file

@ -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))

View file

@ -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');