Sith/counter/schemas.py

30 lines
847 B
Python
Raw Permalink Normal View History

2024-10-12 15:30:19 +00:00
from datetime import datetime
2024-07-18 18:23:30 +00:00
2024-10-12 15:30:19 +00:00
from ninja import FilterSchema, ModelSchema
from pydantic import Field
from counter.models import Counter, Permanency
2024-07-18 18:23:30 +00:00
class CounterSchema(ModelSchema):
class Meta:
model = Counter
2024-10-13 22:48:05 +00:00
fields = ["id", "name", "type"]
2024-10-12 15:30:19 +00:00
class PermanencySchema(ModelSchema):
2024-10-13 22:48:05 +00:00
counter: CounterSchema
2024-10-12 15:30:19 +00:00
class Meta:
model = Permanency
2024-10-13 22:48:05 +00:00
fields = ["start", "end"]
2024-10-12 15:30:19 +00:00
class PermanencyFilterSchema(FilterSchema):
2024-10-20 13:53:02 +00:00
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")
took_place_after: datetime | None = Field(None, q=["start__gte", "end__gte"])
2024-10-12 15:30:19 +00:00
counter: set[int] | None = Field(None, q="counter_id__in")