From 5b330567f8a1fadbccc10b69c0189b3997945da0 Mon Sep 17 00:00:00 2001 From: ticvac Date: Tue, 12 Nov 2024 21:44:17 +0100 Subject: [PATCH] generating file names with three functions --- soustredeni/models.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/soustredeni/models.py b/soustredeni/models.py index 9f7269cb..c8b36741 100644 --- a/soustredeni/models.py +++ b/soustredeni/models.py @@ -15,6 +15,12 @@ import secrets import string from django.utils import timezone +def generate_filename_vcf(self, filename): + return generate_filename_kontaktnicek(self, filename, 'vcf') + +def generate_filemane_pdf(self, filename): + return generate_filename_kontaktnicek(self, filename, 'pdf') + def generate_filename_kontaktnicek(self, filename, file_type): # generate random string length = 32 @@ -77,8 +83,8 @@ class Soustredeni(SeminarModelBase): exportovat = models.BooleanField('export do AESOPa', db_column='exportovat', default=False, help_text='Exportuje se jen podle tohoto flagu (ne veřejnosti)') #using lambda to avoid circular import - kontaktnicek_vcf = models.FileField('kontaktníček vcf', upload_to=lambda instance, filename: generate_filename_kontaktnicek(instance, filename, 'vcf'), blank=True, null=True) - kontaktnicek_pdf = models.FileField('kontaktníček pdf', upload_to=lambda instance, filename: generate_filename_kontaktnicek(instance, filename, 'pdf'), blank=True, null=True) + kontaktnicek_vcf = models.FileField('kontaktníček vcf', upload_to=generate_filename_vcf, blank=True, null=True) + kontaktnicek_pdf = models.FileField('kontaktníček pdf', upload_to=generate_filemane_pdf, blank=True, null=True) def __str__(self): return '{} ({})'.format(self.misto, self.datum_zacatku)