Source

datenaustausch / upload / models.py

Full commit
from django.db import models
from django.contrib.auth.models import User

from hashlib import md5
from os import path

import time

UPLOAD_DIR = "uploaded_files"

class UploadedFile(models.Model):
    owner = models.ForeignKey(User)
    name = models.CharField(max_length=128, blank=False, null=False)
    description = models.TextField(max_length=512)
    created_at = models.DateTimeField("Created at", auto_now=True)
    file_on_fs = models.FileField(upload_to=UPLOAD_DIR)
    download_password = models.CharField(max_length=64, blank=True)

    def is_password_protected(self):
        return any(self.download_password )
    
    def filename(self):
        return path.basename(self.file_on_fs.name)

class UploadTicket(models.Model):
    referenced_file = models.ForeignKey(UploadedFile, null=True, blank=True)
    identifier = models.CharField(max_length=48, blank=True, unique=True)
    created_by = models.ForeignKey(User)
    created_at = models.DateTimeField("Created at", auto_now=True)
    valid_until = models.DateTimeField("Valid until", blank=True)
    
    def is_occupied(self):
        pass

    @classmethod
    def generate_new_id(cls):
        return md5(str(time.time())).hexdigest()