11import hashlib
22import mimetypes
3+ import typing
34
45from core .models import BaseAbstractModel
56from django .core .files .storage import storages
67from django .db import models
78
89
910class PublicFile (BaseAbstractModel ):
11+ choices_meta_schema : typing .ClassVar [dict ] = {
12+ "preview" : {"label" : "미리보기" , "type" : "string" , "display" : "image" },
13+ "mimetype" : {"label" : "형식" , "type" : "string" , "filter" : "select" },
14+ "size" : {"label" : "크기(bytes)" , "type" : "number" },
15+ }
16+
1017 file = models .FileField (unique = True , null = False , blank = False , upload_to = "public/" , storage = storages ["public" ])
1118 mimetype = models .CharField (max_length = 256 , null = True , blank = False )
1219 hash = models .CharField (max_length = 256 , null = False , blank = False )
@@ -19,6 +26,13 @@ class Meta:
1926 def __str__ (self ) -> str :
2027 return self .file .name
2128
29+ def get_choice_meta (self ) -> dict :
30+ return {
31+ "preview" : self .file .url if self .file else None ,
32+ "mimetype" : self .mimetype ,
33+ "size" : self .size ,
34+ }
35+
2236 def clean (self ) -> None :
2337 # 파일의 해시값, 크기, mimetype을 계산하여 저장합니다.
2438 hash_md5 = hashlib .md5 (usedforsecurity = False )
0 commit comments