Sith/counter/schemas.py
2024-10-20 15:53:02 +02:00

29 lines
765 B
Python

from datetime import datetime
from ninja import FilterSchema, ModelSchema
from pydantic import Field
from counter.models import Counter, Permanency
class CounterSchema(ModelSchema):
class Meta:
model = Counter
fields = ["id", "name", "type"]
class PermanencySchema(ModelSchema):
counter: CounterSchema
class Meta:
model = Permanency
fields = ["start", "end"]
class PermanencyFilterSchema(FilterSchema):
start_after: datetime | None = Field(None, q="start__gte")
start_before: datetime | None = Field(None, q="start__lte")
end_after: datetime | None = Field(None, q="end__gte")
end_before: datetime | None = Field(None, q="end__lte")
counter: set[int] | None = Field(None, q="counter_id__in")