• <small id='WAFBf'></small><noframes id='WAFBf'>

  • <legend id='WAFBf'><style id='WAFBf'><dir id='WAFBf'><q id='WAFBf'></q></dir></style></legend>

    1. <i id='WAFBf'><tr id='WAFBf'><dt id='WAFBf'><q id='WAFBf'><span id='WAFBf'><b id='WAFBf'><form id='WAFBf'><ins id='WAFBf'></ins><ul id='WAFBf'></ul><sub id='WAFBf'></sub></form><legend id='WAFBf'></legend><bdo id='WAFBf'><pre id='WAFBf'><center id='WAFBf'></center></pre></bdo></b><th id='WAFBf'></th></span></q></dt></tr></i><div id='WAFBf'><tfoot id='WAFBf'></tfoot><dl id='WAFBf'><fieldset id='WAFBf'></fieldset></dl></div>
        <bdo id='WAFBf'></bdo><ul id='WAFBf'></ul>

      <tfoot id='WAFBf'></tfoot>

        Django 删除未使用的媒体文件

        Django delete unused media files(Django 删除未使用的媒体文件)

        <i id='WnDDk'><tr id='WnDDk'><dt id='WnDDk'><q id='WnDDk'><span id='WnDDk'><b id='WnDDk'><form id='WnDDk'><ins id='WnDDk'></ins><ul id='WnDDk'></ul><sub id='WnDDk'></sub></form><legend id='WnDDk'></legend><bdo id='WnDDk'><pre id='WnDDk'><center id='WnDDk'></center></pre></bdo></b><th id='WnDDk'></th></span></q></dt></tr></i><div id='WnDDk'><tfoot id='WnDDk'></tfoot><dl id='WnDDk'><fieldset id='WnDDk'></fieldset></dl></div>

        <legend id='WnDDk'><style id='WnDDk'><dir id='WnDDk'><q id='WnDDk'></q></dir></style></legend>
          <tbody id='WnDDk'></tbody>
          • <tfoot id='WnDDk'></tfoot>

                • <bdo id='WnDDk'></bdo><ul id='WnDDk'></ul>
                • <small id='WnDDk'></small><noframes id='WnDDk'>

                  本文介绍了Django 删除未使用的媒体文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 django 项目,管理员可以在其中上传媒体.随着商品的销售,它们会从站点中删除,从而删除它们在 MySQL 数据库中的条目.但是,与该项目关联的图像仍保留在文件系统中.这不一定是坏行为——我不介意保留文件以防意外删除.我预见到的问题是从现在开始的两年后,由于存储空间有限,因为媒体文件夹中充斥着旧产品图片.

                  I have a django project in which the admins are able to upload media. As items sell, they are deleted from the site, thus removing their entry in the MySQL database. The images associated with the item, however, remain on the file system. This isn't neccessarily bad behavior - I don't mind keeping files around in case a deletion was an accident. The problem I forsee is two years from now, when storage space is limited because of a media folder bloated with old product images.

                  有没有人知道一种系统/编程的方式来对所有图像进行排序并将它们与相关的 MySQL 字段进行比较,从文件系统中删除任何不匹配的图像?在完美的世界中,我想象 django-admin 中的一个按钮,例如清理未使用的媒体",它执行一个能够执行此行为的 python 脚本.我将在这里分享我的最终解决方案,但我现在正在寻找的是任何有想法、了解资源或在某个时候自己做过这件事的人.

                  Does anyone know of a systematic/programmatic way to sort through ALL the images and compare them to the relevant MySQL fields, deleting any image which DOESN'T have a match from the filesystem? In the perfect world I'm imagining a button in the django-admin like "Clean-up unused media" which executes a python script capable of this behavior. I'll be sharing whatever my eventual solution is here, but what I'm looking for right now is anyone who has ideas, knows resources, or has done this at some point themselves.

                  推荐答案

                  试试 django-cleanup,当你删除模型时,它会自动调用 FileField 上的 delete 方法.

                  Try django-cleanup, it automatically invokes delete method on FileField when you remove model.

                  pip install django-cleanup
                  

                  settings.py

                  settings.py

                  INSTALLED_APPS = (
                       ...
                      'django_cleanup.apps.CleanupConfig', # should go after your apps
                  )
                  

                  这篇关于Django 删除未使用的媒体文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
                    <bdo id='l3OAB'></bdo><ul id='l3OAB'></ul>

                        • <i id='l3OAB'><tr id='l3OAB'><dt id='l3OAB'><q id='l3OAB'><span id='l3OAB'><b id='l3OAB'><form id='l3OAB'><ins id='l3OAB'></ins><ul id='l3OAB'></ul><sub id='l3OAB'></sub></form><legend id='l3OAB'></legend><bdo id='l3OAB'><pre id='l3OAB'><center id='l3OAB'></center></pre></bdo></b><th id='l3OAB'></th></span></q></dt></tr></i><div id='l3OAB'><tfoot id='l3OAB'></tfoot><dl id='l3OAB'><fieldset id='l3OAB'></fieldset></dl></div>
                            <tbody id='l3OAB'></tbody>

                            <small id='l3OAB'></small><noframes id='l3OAB'>

                            <legend id='l3OAB'><style id='l3OAB'><dir id='l3OAB'><q id='l3OAB'></q></dir></style></legend>
                          1. <tfoot id='l3OAB'></tfoot>