2👍
✅
Yes, take a look at the documentation on upload_to
.
You could do something like this, which includes the node
id (defined as an integer in your model in the upload_to
path:
def attachment_path_with_node(instance, filename):
return "attachments/{}/{}".format(instance.node, filename)
class Attachment(models.Model):
node = models.IntegerField(default=-1)
file = models.FileField(upload_to=attachment_path_with_node)
0👍
Also path can be further customized like this:
document = models.FileField(upload_to='documents/%Y/%m/%d/')
which would upload to: MEDIA_ROOT/documents/2020/12/22/
.
See more at https://simpleisbetterthancomplex.com/tutorial/2016/08/01/how-to-upload-files-with-django.html
- [Answered ]-How to serve a text file at root with Django
- [Answered ]-Pip is rolling back uninstall of setuptools
- [Answered ]-Django app failed to connect with ms sql server 2014
Source:stackexchange.com