英文:
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
创建一个自定义中间件并将其添加到您的设置文件中。
```python
from admin_reorder.middleware import ModelAdminReorder
class ModelAdminReorderWithNav(ModelAdminReorder):
def process_template_response(self, request, response):
available_apps = response.context_data.get('available_apps')
response.context_data['app_list'] = available_apps
response = super().process_template_response(request, response)
response.context_data['available_apps'] = response.context_data['app_list']
return response
<details>
<summary>英文:</summary>
Create a custom middleware and add it in your settings file.
from admin_reorder.middleware import ModelAdminReorder
class ModelAdminReorderWithNav(ModelAdminReorder):
def process_template_response(self, request, response):
available_apps = response.context_data.get('available_apps')
response.context_data['app_list'] = available_apps
response = super().process_template_response(request, response)
response.context_data['available_apps'] = response.context_data[
'app_list'
]
return response
</details>
# 答案2
**得分**: 0
有关当前的重新排序包存在问题 - 看起来它没有得到维护。我遇到了完全相同的问题,但我发现已经有一个解决此问题的PR存在。
您可以访问[问题][1],并通过 GitHub 存储库获取此库,而不是直接使用包名称。
希望有所帮助。
[1]: https://github.com/mishbahr/django-modeladmin-reorder/issues/47#issuecomment-674782623
<details>
<summary>英文:</summary>
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.
You can navigate to the [issue][1] and fetch the lib through a github repo, instead of using it directly under the package name.
Hope it helps.
[1]: https://github.com/mishbahr/django-modeladmin-reorder/issues/47#issuecomment-674782623
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论