from rest_framework import serializers

class FileUrlField(serializers.FileField):
    """
    Custom FileField that always returns a URL or string path,
    never a FieldFile instance.
    """
    def to_representation(self, value):
        if not value:
            return None
        try:
            return value.url   # absolute URL if MEDIA_URL is configured
        except Exception:
            return str(value)  # fallback: relative path
