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.
 
 
 
 

41 lines
1.2 KiB

from rest_framework import serializers
from apps.dobodbi_calendar.models import CalendarOccasions
class CalendarOccasionAdminSerializer(serializers.ModelSerializer):
dates = serializers.ListField(child=serializers.DictField(), allow_empty=False)
class Meta:
model = CalendarOccasions
fields = [
"id",
"title",
"is_global",
"occasion_type",
"dates",
"is_yearly",
"event_type",
"updated_at",
"created_at",
]
read_only_fields = ["id", "updated_at", "created_at"]
def validate_dates(self, value):
cleaned_dates = []
for index, item in enumerate(value):
day = str(item.get("day", "")).strip()
month = str(item.get("month", "")).strip()
year = str(item.get("year", "")).strip()
if not day or not month:
raise serializers.ValidationError(f"Date row {index + 1} must include day and month.")
cleaned_dates.append({
"day": day,
"month": month,
"year": year,
})
return cleaned_dates