This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
static-share/project/files/models.py

31 lines
939 B
Python
Raw Normal View History

2016-09-05 18:53:18 +01:00
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:])