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

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

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(&#39;available_apps&#39;)
    
            response.context_data[&#39;app_list&#39;] = available_apps
    
            response = super().process_template_response(request, response)
    
            response.context_data[&#39;available_apps&#39;] = response.context_data[
    
                &#39;app_list&#39;
    
            ]
    
            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>



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:

确定