需要使用django admin的jazzmin包将应用程序分组到侧边栏标签下。

huangapple go评论121阅读模式
英文:

Need to group the apps under labels for the sidebar of django admin using the package jazzmin

问题

我已成功将仪表板主页上的应用程序分组。但是在侧边栏中没有反映出来。我需要在侧边栏中也分组模型。

我使用了jazzmin包以及admin_reorder包。

使用的包是:
django-modeladmin-reorder==0.3.1 和
django-reorder-admin==0.3.1

英文:

I have managed to group the apps in the landaing page of dashboard. But in side bar it was not refelcting. i need to group the models in the side bar too.

i have used the jazzmin package as well as the admin_reorder

packages used are :-
django-modeladmin-reorder==0.3.1 and
django-reorder-admin==0.3.1

答案1

得分: 1

  1. 创建一个自定义中间件并将其添加到您的设置文件中
  2. ```python
  3. from admin_reorder.middleware import ModelAdminReorder
  4. class ModelAdminReorderWithNav(ModelAdminReorder):
  5. def process_template_response(self, request, response):
  6. available_apps = response.context_data.get('available_apps')
  7. response.context_data['app_list'] = available_apps
  8. response = super().process_template_response(request, response)
  9. response.context_data['available_apps'] = response.context_data['app_list']
  10. return response
  1. <details>
  2. <summary>英文:</summary>
  3. Create a custom middleware and add it in your settings file.
  4. from admin_reorder.middleware import ModelAdminReorder
  5. class ModelAdminReorderWithNav(ModelAdminReorder):
  6. def process_template_response(self, request, response):
  7. available_apps = response.context_data.get(&#39;available_apps&#39;)
  8. response.context_data[&#39;app_list&#39;] = available_apps
  9. response = super().process_template_response(request, response)
  10. response.context_data[&#39;available_apps&#39;] = response.context_data[
  11. &#39;app_list&#39;
  12. ]
  13. return response
  14. </details>
  15. # 答案2
  16. **得分**: 0
  17. 有关当前的重新排序包存在问题 - 看起来它没有得到维护。我遇到了完全相同的问题,但我发现已经有一个解决此问题的PR存在。
  18. 您可以访问[问题][1],并通过 GitHub 存储库获取此库,而不是直接使用包名称。
  19. 希望有所帮助。
  20. [1]: https://github.com/mishbahr/django-modeladmin-reorder/issues/47#issuecomment-674782623
  21. <details>
  22. <summary>英文:</summary>
  23. There is an issue with the current reorder package - it looks like it is not maintained. I had exactly the same issue but I found that a PR exists, that solves this issue.
  24. You can navigate to the [issue][1] and fetch the lib through a github repo, instead of using it directly under the package name.
  25. Hope it helps.
  26. [1]: https://github.com/mishbahr/django-modeladmin-reorder/issues/47#issuecomment-674782623
  27. </details>

huangapple
  • 本文由 发表于 2023年6月27日 20:07:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76564699.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定