Sith/counter/schemas.py

45 lines
1.0 KiB
Python
Raw Normal View History

2024-10-12 15:30:19 +00:00
from datetime import datetime
from typing import Annotated
from annotated_types import MinLen
from ninja import Field, FilterSchema, ModelSchema
2024-10-12 15:30:19 +00:00
from pydantic import Field
2024-07-18 18:23:30 +00:00
2024-10-12 15:30:19 +00:00
from counter.models import Counter, Permanency, Product
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")
class CounterFilterSchema(FilterSchema):
search: Annotated[str, MinLen(1)] = Field(None, q="name__icontains")
class SimplifiedCounterSchema(ModelSchema):
class Meta:
model = Counter
fields = ["id", "name"]
class ProductSchema(ModelSchema):
class Meta:
model = Product
fields = ["id", "name", "code"]