Sith/counter/schemas.py
2024-10-14 01:05:33 +02:00

27 lines
639 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_date: datetime | None = Field(None, q="start__gte")
end_date: datetime | None = Field(None, q="end__lte")
counter: set[int] | None = Field(None, q="counter_id__in")