I'm trying to call the property protocolo on a new imagefield's upload_to argument
What I'm trying to accomplish is to have the saved images use a custom filename.
class biopsia(models.Model):
paciente = models.CharField(max_length=50)
creado = models.DateTimeField(auto_now_add=True)
foto = models.ImageField(upload_to=f'fotos_biopsias/%Y/{protocolo}', blank=True)
def __str__(self):
return str(self.protocolo)
@property
def protocolo(self):
return 'BIO' + str(self.creado.year) + '-' + str(biopsia._base_manager.filter(
creado__year=self.creado.year,
creado__lt=self.creado
).count() + 1)
File "models.py", line 30, in biopsia
foto = models.ImageField(upload_to=f'fotos_biopsias/%Y/{protocolo}', blank=True)
NameError: name 'protocolo' is not defined
I've tried defining an outside method for upload_to but still I cannot use it inside my class