Create dedicated image upload model

This commit is contained in:
2025-02-28 15:06:47 +01:00
parent 7b23196071
commit c236092c4f
9 changed files with 149 additions and 59 deletions

View File

@ -10,10 +10,9 @@ from django.utils.translation import gettext as _
from haystack.query import SearchQuerySet
from ninja import FilterSchema, ModelSchema, Schema, UploadedFile
from pydantic import AliasChoices, Field
from pydantic_core import Url
from pydantic_core.core_schema import ValidationInfo
from core.models import Group, SithFile, User
from core.models import Group, QuickUploadImage, SithFile, User
from core.utils import is_image
@ -63,14 +62,29 @@ class UserProfileSchema(ModelSchema):
class UploadedFileSchema(ModelSchema):
class Meta:
model = SithFile
fields = ["id", "name", "mime_type", "size"]
model = QuickUploadImage
fields = ["uuid", "name", "content_type"]
width: int
height: int
size: int
href: str
@staticmethod
def resolve_href(obj: SithFile) -> Url:
return reverse("core:download", kwargs={"file_id": obj.id})
def resolve_width(obj: QuickUploadImage):
return obj.image.width
@staticmethod
def resolve_height(obj: QuickUploadImage):
return obj.image.height
@staticmethod
def resolve_size(obj: QuickUploadImage):
return obj.image.size
@staticmethod
def resolve_href(obj: QuickUploadImage) -> str:
return obj.get_absolute_url()
class SithFileSchema(ModelSchema):