Add: Metadata file model & reverse url

This commit is contained in:
Aroy-Art 2024-01-02 21:11:20 +01:00
parent fcee63998e
commit 3325a6890e
Signed by: Aroy
GPG key ID: 583642324A1D2070

View file

@ -1,4 +1,5 @@
from django.db import models from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -7,6 +8,9 @@ from django.utils.translation import gettext_lazy as _
def get_upload_to(instance, filename, folder): def get_upload_to(instance, filename, folder):
return f'{folder}/{instance.file_hash[:2]}/{filename}' return f'{folder}/{instance.file_hash[:2]}/{filename}'
def get_upload_to_metadata(instance, filename):
return get_upload_to(instance, filename, 'metadata')
def get_upload_to_submission(instance, filename): def get_upload_to_submission(instance, filename):
return get_upload_to(instance, filename, 'submissions') return get_upload_to(instance, filename, 'submissions')
@ -29,10 +33,10 @@ class User_Profile_Images(models.Model):
verbose_name_plural = _("User Profile Images") verbose_name_plural = _("User Profile Images")
def __str__(self): def __str__(self):
return self.name return self.file_name
#def get_absolute_url(self): def get_absolute_url(self):
# return reverse("User_Profile_Image_detail", kwargs={"pk": self.pk}) return reverse('serve_content_file', args=['user_profile', self.file_hash])
class User_Banner_Images(models.Model): class User_Banner_Images(models.Model):
@ -47,7 +51,10 @@ class User_Banner_Images(models.Model):
verbose_name_plural = _("User Banner Images") verbose_name_plural = _("User Banner Images")
def __str__(self): def __str__(self):
return self.name return self.file_name
def get_absolute_url(self):
return reverse('serve_content_file', args=['user_banner', self.file_hash])
class Submission_File(models.Model): class Submission_File(models.Model):
@ -62,4 +69,25 @@ class Submission_File(models.Model):
verbose_name_plural = _("Submission Files") verbose_name_plural = _("Submission Files")
def __str__(self): def __str__(self):
return self.file_hash return self.file_name
def get_absolute_url(self):
return reverse('serve_content_file', args=['submission', self.file_hash])
class Metadata_Files(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_metadata, blank=True)
date_added = models.DateTimeField(auto_now_add=True, editable=True)
class Meta:
verbose_name = _("Metadata File")
verbose_name_plural = _("Metadata Files")
def __str__(self):
return self.file_name
def get_absolute_url(self):
return reverse('serve_content_file', args=['metadata', self.file_hash])