16 lines
690 B
Python

from rest_framework import serializers
from ..models import AiModel
class AiModelSerializer(serializers.ModelSerializer):
# Read-only field สำหรับแสดงผล Full URL ที่ DRF จะใช้ Proxy
full_endpoint = serializers.SerializerMethodField()
class Meta:
model = AiModel
fields = '__all__'
read_only_fields = ('created_at', 'updated_at', 'full_endpoint')
def get_full_endpoint(self, obj: AiModel) -> str:
return obj.full_inference_url()
# สามารถเพิ่ม Custom Validation ที่นี่: เช่น ตรวจสอบความถูกต้องของ base_url format