2024-07-18 18:23:30 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
2024-07-25 15:27:23 +00:00
|
|
|
from ninja import FilterSchema, ModelSchema, Schema
|
|
|
|
from pydantic import Field, NonNegativeInt
|
2024-07-18 18:23:30 +00:00
|
|
|
|
|
|
|
from core.schemas import SimpleUserSchema
|
2024-07-25 15:27:23 +00:00
|
|
|
from sas.models import PeoplePictureRelation, Picture
|
2024-07-18 18:23:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PictureFilterSchema(FilterSchema):
|
|
|
|
before_date: datetime | None = Field(None, q="date__lte")
|
|
|
|
after_date: datetime | None = Field(None, q="date__gte")
|
|
|
|
users_identified: set[int] | None = Field(None, q="people__user_id__in")
|
|
|
|
album_id: int | None = Field(None, q="parent_id")
|
|
|
|
|
|
|
|
|
|
|
|
class PictureSchema(ModelSchema):
|
|
|
|
class Meta:
|
|
|
|
model = Picture
|
2024-07-23 22:37:35 +00:00
|
|
|
fields = ["id", "name", "date", "size"]
|
2024-07-18 18:23:30 +00:00
|
|
|
|
|
|
|
author: SimpleUserSchema = Field(validation_alias="owner")
|
|
|
|
full_size_url: str
|
|
|
|
compressed_url: str
|
|
|
|
thumb_url: str
|
2024-07-25 15:27:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PictureCreateRelationSchema(Schema):
|
|
|
|
user_id: NonNegativeInt
|
|
|
|
picture_id: NonNegativeInt
|
|
|
|
|
|
|
|
|
|
|
|
class CreatedPictureRelationSchema(ModelSchema):
|
|
|
|
class Meta:
|
|
|
|
model = PeoplePictureRelation
|
|
|
|
fields = ["id", "user", "picture"]
|