# Path: backend/api/serializers/page.py
# class PageListSerializer(serializers.HyperlinkedModelSerializer):
#     class Meta:
#         model = Page
#         fields = ('name', 'slug')
# 
# class PageDetailSerializer(PageListSerializer):
#     class Meta(PageListSerializer.Meta):
#         fields = ('name', 'slug', 'content')
# 
# Path: backend/api/viewsets/utils.py
# class MultiSerializerViewSet(ModelViewSet):
#     serializers = {
#         'default': None,
#     }
# 
#     def get_serializer_class(self):
#         return self.serializers.get(self.action, self.serializers['default'])


from ..serializers import PageListSerializer, PageDetailSerializer
from rest_framework.viewsets import ModelViewSet
from pages.models import Page
from .utils import MultiSerializerViewSet


class PageViewSet(MultiSerializerViewSet):
    model = Page
    queryset = Page.objects.filter(is_enabled=True)

    serializers = {
        'default': PageListSerializer,
        'retrieve': PageDetailSerializer,
    }

    lookup_field = 'slug'

# Path: backend/api/serializers/page.py
# class PageListSerializer(serializers.HyperlinkedModelSerializer):
#     class Meta:
#         model = Page
#         fields = ('name', 'slug')
# 
# class PageDetailSerializer(PageListSerializer):
#     class Meta(PageListSerializer.Meta):
#         fields = ('name', 'slug', 'content')
# 
# Path: backend/api/viewsets/utils.py
# class MultiSerializerViewSet(ModelViewSet):
#     serializers = {
#         'default': None,
#     }
# 
#     def get_serializer_class(self):
#         return self.serializers.get(self.action, self.serializers['default'])


# Path: backend/api/viewsets/page.py
from ..serializers import PageListSerializer, PageDetailSerializer
from rest_framework.viewsets import ModelViewSet
from pages.models import Page
from .utils import MultiSerializerViewSet



class PageViewSet(MultiSerializerViewSet):
    model = Page
    queryset = Page.objects.filter(is_enabled=True)

    serializers = {
        'default': PageListSerializer,
        'retrieve': PageDetailSerializer,
    }

    lookup_field = 'slug'

    lookup_value_regex = '[0-9a-z\-_]+'