from django.db import models from django.utils.translation import gettext_lazy as _ # Create your models here. def get_upload_to(instance, filename, folder): return f'{folder}/{instance.file_hash[:2]}/{filename}' def get_upload_to_submission(instance, filename): return get_upload_to(instance, filename, 'submissions') def get_upload_to_profile(instance, filename): return get_upload_to(instance, filename, 'profiles') def get_upload_to_banner(instance, filename): return get_upload_to(instance, filename, 'banners') class User_Profile_Images(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_profile, blank=True) date_added = models.DateTimeField(auto_now_add=True, editable=True) class Meta: verbose_name = _("User Profile Image") verbose_name_plural = _("User Profile Images") def __str__(self): return self.name #def get_absolute_url(self): # return reverse("User_Profile_Image_detail", kwargs={"pk": self.pk}) class User_Banner_Images(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_banner, blank=True) date_added = models.DateTimeField(auto_now_add=True, editable=True) class Meta: verbose_name = _("User Banner Image") verbose_name_plural = _("User Banner Images") def __str__(self): return self.name 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_submission, 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