避免缩略图名称与 sorl-thumbnail 发生冲突

发布于 2024-08-27 04:05:19 字数 359 浏览 4 评论 0原文

我知道我可能应该深入研究源代码来找到解决方案,我想知道是否有人想出了解决这个问题的策略。

在我的项目中,我有很多图像是在应用程序外部生成的。我根据模型的 pk 将它们隔离在文件系统上。

例如,pk 为 121 的模型实例可能具有以下图像:

.../src_pics/1/2/1/img.1.jpg
.../src_pics/1/2/1/img.2.jpg
...
.../src_pics/1/2/1/img.27.jpg

由于图像文件名本身不能保证是唯一的,因此我正在寻找一种方法来通知 sorl(在运行时)我想要添加前缀对该模型的评价以及实例 pk 值。这甚至可以在不修补 sorl 的情况下实现吗?

Understanding that I should probably just dig into the source to come up with a solution, I'm wondering if anyone has come up with a tactic for dealing with this.

In my project, I have a lot of images being generated outside of the application. I'm isolating them on the filesystem based on a model's pk.

For example, a model instance with a pk of 121 might have the following images:

.../src_pics/1/2/1/img.1.jpg
.../src_pics/1/2/1/img.2.jpg
...
.../src_pics/1/2/1/img.27.jpg

Since the image filenames themselves are not guaranteed to be unique, I'm looking for a way to inform sorl (at runtime) that I'd like to prefix thumbs for this model with the instance pk value. Is this even possible without patching sorl?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷路的信 2024-09-03 04:05:19

啊哈。
看来解决方案一直在我面前。
http://thumbnail.sorl.net/docs /#this-just-doesn-t-cover-my-cravings

看起来我要子类化 sorl.thumbnail.main.DjangoThumbnail 并重新实现 _get_relative_thumbnail 方法以允许我注入< /em> 缩略图文件名的模板驱动前缀。

Ah hah.
Well it looks like the solution was staring me in the face the whole time.
http://thumbnail.sorl.net/docs/#this-just-doesn-t-cover-my-cravings

Looks like I'm going to subclass sorl.thumbnail.main.DjangoThumbnail and re-implement the _get_relative_thumbnail method to allow me to inject a template driven prefix for the thumbnail filename.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文