create basic model
This commit is contained in:
parent
d6f337c274
commit
0528359ce8
1 changed files with 30 additions and 0 deletions
30
project/files/models.py
Normal file
30
project/files/models.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from django.db import models
|
||||
import os
|
||||
import uuid
|
||||
from admin_resumable.fields import ModelAdminResumableFileField
|
||||
from shortuuidfield import ShortUUIDField
|
||||
|
||||
|
||||
def build_save_path(obj, filename):
|
||||
return obj.get_save_path(filename)
|
||||
|
||||
|
||||
class SharedFile(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
short_id = ShortUUIDField()
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
file = ModelAdminResumableFileField(upload_to=build_save_path)
|
||||
hotlink = models.BooleanField(default=False)
|
||||
published = models.BooleanField(default=True)
|
||||
|
||||
filename = ""
|
||||
|
||||
def get_save_path(self, filename):
|
||||
self.filename = filename
|
||||
return os.path.join(str(self.id), str(self.short_id), filename)
|
||||
|
||||
def get_private_path(self):
|
||||
return self.get_save_path(self.filename)
|
||||
|
||||
def get_original_filename(self):
|
||||
return "_".join(self.file.name.split('_')[1:])
|
Reference in a new issue