2023-12-28 17:38:25 +01:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
|
|
# Create your models here.
|
|
|
|
|
2023-12-29 22:45:15 +01:00
|
|
|
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
|
|
|
|
|
2023-12-28 17:38:25 +01:00
|
|
|
|
|
|
|
class Submission_File(models.Model):
|
|
|
|
|
|
|
|
file_hash = models.CharField(unique=True, max_length=64,)
|
|
|
|
file_name = models.CharField(max_length=150, blank=True)
|
2023-12-29 22:45:15 +01:00
|
|
|
file = models.FileField(upload_to=get_upload_to_submission, blank=True)
|
2023-12-28 17:38:25 +01:00
|
|
|
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
|