mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-19 09:34:38 +00:00
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from rest_framework import serializers
|
|
from .models import EPGSource, EPGData, ProgramData
|
|
from apps.channels.models import Channel
|
|
|
|
class EPGSourceSerializer(serializers.ModelSerializer):
|
|
epg_data_ids = serializers.SerializerMethodField()
|
|
read_only_fields = ['created_at', 'updated_at']
|
|
|
|
class Meta:
|
|
model = EPGSource
|
|
fields = ['id', 'name', 'source_type', 'url', 'api_key', 'is_active', 'epg_data_ids', 'refresh_interval', 'created_at', 'updated_at']
|
|
|
|
def get_epg_data_ids(self, obj):
|
|
return list(obj.epgs.values_list('id', flat=True))
|
|
|
|
class ProgramDataSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = ProgramData
|
|
fields = ['id', 'start_time', 'end_time', 'title', 'sub_title', 'description', 'tvg_id']
|
|
|
|
class EPGDataSerializer(serializers.ModelSerializer):
|
|
"""
|
|
Only returns the tvg_id and the 'name' field from EPGData.
|
|
We assume 'name' is effectively the channel name.
|
|
"""
|
|
read_only_fields = ['epg_source']
|
|
|
|
class Meta:
|
|
model = EPGData
|
|
fields = [
|
|
'id',
|
|
'tvg_id',
|
|
'name',
|
|
'epg_source',
|
|
]
|