Browse Source

generating file names with three functions

pull/74/head^2
ticvac 1 month ago
parent
commit
5b330567f8
  1. 10
      soustredeni/models.py

10
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)

Loading…
Cancel
Save