from typing import Type

from rest_framework import serializers

from apps.geology.models import Category, Geology


class CategorySerializer(serializers.ModelSerializer):
    count = serializers.SerializerMethodField()

    class Meta:
        model: Type[Category] = Category
        fields: str = ("id", "count", "name", "created_at", "updated_at")

    def get_count(self, obj):
        return Geology.objects.filter(category=obj).count()
