1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-18 20:39:36 +02:00
AdventureLog/backend/server/adventures/serializers.py

19 lines
711 B
Python
Raw Normal View History

2024-07-08 11:44:39 -04:00
import os
from .models import Adventure
from rest_framework import serializers
class AdventureSerializer(serializers.ModelSerializer):
class Meta:
model = Adventure
fields = '__all__' # Serialize all fields of the Adventure model
def to_representation(self, instance):
representation = super().to_representation(instance)
if instance.image:
public_url = os.environ.get('PUBLIC_URL', 'http://127.0.0.1:8000').rstrip('/')
print(public_url)
# remove any ' from the url
public_url = public_url.replace("'", "")
representation['image'] = f"{public_url}/media/{instance.image.name}"
return representation