The dynamic path for Upload_to in the Django model (Models.filefield)
📁 lambda, Advanced Python Topics, django, AI
Hello, in Django up to version 1.4 there was the ability in the model for models.filefield to specify "dynamically" "the created path for storing files in the variable Upload_to
Models.py
#...
attach = models.FileField(verbose_name=u'Photo', blank=True, upload_to=lambda instance, filename: 'attach/%s/%s'%(instance.id, filename))
In Django version 1.4, the ID is assigned later and therefore instance.id = None and also instance.pk = None. Tell me how to specify the model ID in the path.
No answers yet.
Log in to leave an answer
Blogs