mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-11 04:19:25 +00:00
Add API endpoint to upload images
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user