Gallery-Archivist/archivist/apps/files/models.py

22 lines
693 B
Python

from django.db import models
from django.utils.translation import gettext_lazy as _
# Create your models here.
def get_upload_to(instance, filename):
return f'submissions/{instance.file_hash[:2]}/{filename}'
class Submission_File(models.Model):
file_hash = models.CharField(unique=True, max_length=64,)
file_name = models.CharField(max_length=150, blank=True)
file = models.FileField(upload_to=get_upload_to, blank=True)
date_added = models.DateTimeField(auto_now_add=True, editable=True)
class Meta:
verbose_name = _("Submission File")
verbose_name_plural = _("Submission Files")
def __str__(self):
return self.file_hash