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

30 lines
1 KiB
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
2016-09-06 08:48:48 +01:00
from datetime import timedelta
2016-09-05 18:53:18 +01:00
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)
2016-09-06 08:48:48 +01:00
file = ModelAdminResumableFileField()
2016-09-05 18:53:18 +01:00
hotlink = models.BooleanField(default=False)
published = models.BooleanField(default=True)
2016-09-06 08:48:48 +01:00
def get_original_filename(self):
return "_".join(self.file.name.split('_')[1:])
2016-09-05 18:53:18 +01:00
2016-09-06 08:48:48 +01:00
class FileToken(models.Model):
valid_time = timedelta(minutes=5)
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
token = ShortUUIDField()
file = models.ForeignKey(SharedFile, null=False, blank=False, related_name="tokens")
created = models.DateTimeField(auto_now_add=True)
2016-09-05 18:53:18 +01:00
2016-09-06 08:48:48 +01:00
def __str__(self):
return "Token for {0} created at {1}".format(self.file.file.name, self.created)