如何使用django-ckeditor为不同机型指定不同的图片上传路径?
How to use django-ckeditor to specify different image upload paths for different models?
通常的做法是在settings.py
中定义CKEDITOR_UPLOAD_PATH = 'uploads/'
。但这会将所有模型中的图像保存在一个唯一的路径中。是否可以为每个模型分配不同的图像路径?
class BlogModel(models.Model):
......
content = RichTextUploadingField() # image upload to /media/blog/
class NewsModel(models.Model):
......
content = RichTextUploadingField() # image upload to /media/news/
您可以使用 FileField 分配路径 upload_to='pathname'
class BlogModel(models.Model)
content = models.FileField(upload_to='blog/')
class NewsModel(models.Model)
content = models.FileField(upload_to='news/')
Blogmodel内容将上传至/media/blog/
Newsmodel 内容将上传至/media/news/
您还可以这样做:
content = models.FileField(upload_to='pathname/%Y/%m/%d/')
将保存为 /pathname/2019/04/04/
通常的做法是在settings.py
中定义CKEDITOR_UPLOAD_PATH = 'uploads/'
。但这会将所有模型中的图像保存在一个唯一的路径中。是否可以为每个模型分配不同的图像路径?
class BlogModel(models.Model):
......
content = RichTextUploadingField() # image upload to /media/blog/
class NewsModel(models.Model):
......
content = RichTextUploadingField() # image upload to /media/news/
您可以使用 FileField 分配路径 upload_to='pathname'
class BlogModel(models.Model)
content = models.FileField(upload_to='blog/')
class NewsModel(models.Model)
content = models.FileField(upload_to='news/')
Blogmodel内容将上传至/media/blog/
Newsmodel 内容将上传至/media/news/
您还可以这样做:
content = models.FileField(upload_to='pathname/%Y/%m/%d/')
将保存为 /pathname/2019/04/04/