Add API endpoint to upload images

This commit is contained in:
2025-02-26 23:15:26 +01:00
parent 60fd72917d
commit 10367d21ab
3 changed files with 79 additions and 2 deletions

View File

@ -10,6 +10,7 @@ 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
@ -60,6 +61,18 @@ class UserProfileSchema(ModelSchema):
return reverse("core:download", kwargs={"file_id": obj.profile_pict_id})
class UploadedFileSchema(ModelSchema):
class Meta:
model = SithFile
fields = ["id", "name", "mime_type", "size"]
href: str
@staticmethod
def resolve_href(obj: SithFile) -> Url:
return reverse("core:download", kwargs={"file_id": obj.id})
class SithFileSchema(ModelSchema):
class Meta:
model = SithFile