You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1019 B
34 lines
1019 B
from rest_framework import serializers
|
|
|
|
from apps.dobodbi_calendar.models import CalendarOccasions
|
|
|
|
|
|
class CalendarSerializer(serializers.ModelSerializer):
|
|
type = serializers.CharField(source='occasion_type')
|
|
dates = serializers.SerializerMethodField()
|
|
|
|
|
|
# def get_countries(self, obj):
|
|
# if not obj.countries or obj.countries[0] == 'ALL':
|
|
# return ["All"]
|
|
|
|
# return [country.name or country.code for country in obj.countries]
|
|
|
|
# def get_holiday_in_countries(self, obj):
|
|
# return [country.name or country.code for country in obj.holiday_in_countries]
|
|
|
|
def get_dates(self, obj):
|
|
dates = []
|
|
for date in obj.dates:
|
|
dates.append({
|
|
'day': str(date['day']),
|
|
'month': str(date['month']),
|
|
'year': str(date.get('year', '')),
|
|
})
|
|
return dates
|
|
|
|
|
|
class Meta:
|
|
model = CalendarOccasions
|
|
fields = ('id', 'title', 'type', 'event_type', 'dates', 'is_yearly',)
|
|
|