Sith/counter/schemas.py

27 lines
639 B
Python
Raw 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):
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")