create basic model

This commit is contained in:
Jake Howard 2016-09-05 18:53:18 +01:00
parent d6f337c274
commit 0528359ce8
Signed by: jake
GPG key ID: 57AFB45680EDD477

30
project/files/models.py Normal file
View 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:])