1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-04 20:55:19 +02:00

feat: Add flag URL to Country type and update CountryCard component

This commit is contained in:
Sean Morley 2024-08-05 14:17:41 -04:00
parent 77c11fefea
commit d9e554ad42
14 changed files with 96 additions and 56 deletions

View file

@ -1,13 +1,24 @@
import os
from .models import Country, Region, VisitedRegion
from rest_framework import serializers
class CountrySerializer(serializers.ModelSerializer):
def get_public_url(self, obj):
return os.environ.get('PUBLIC_URL', 'http://127.0.0.1:8000').rstrip('/')
flag_url = serializers.SerializerMethodField()
def get_flag_url(self, obj):
public_url = self.get_public_url(obj)
return public_url + '/media/' + 'flags/' + obj.country_code + '.png'
class Meta:
model = Country
fields = '__all__' # Serialize all fields of the Adventure model
class RegionSerializer(serializers.ModelSerializer):
flag_url = ''
class Meta:
model = Region
fields = '__all__' # Serialize all fields of the Adventure model