Add: Profile & Banner image models
This commit is contained in:
parent
dcb53001d2
commit
ddc2259621
1 changed files with 46 additions and 3 deletions
|
@ -4,14 +4,57 @@ 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}'
|
||||
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, 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:
|
||||
|
|
Loading…
Reference in a new issue