Django admin performance issue

后端 未结 2 1734
孤独总比滥情好
孤独总比滥情好 2021-01-21 21:51

I\'m getting thousands of these queries when I try to open up a model in the Django admin interface and it\'s leading to a serious performance issue.

[sql] SELEC         


        
相关标签:
2条回答
  • 2021-01-21 22:04

    Or just enable list_select_related.

    class MyModelAdmin(admin.ModelAdmin):
        list_select_related = True
        # ....
    
    0 讨论(0)
  • 2021-01-21 22:12

    You could make Django use select_related by defining your own ModelAdmin like this

    class MyModelAdmin(admin.ModelAdmin):
        def queryset(self, request):
            qs = super(MyModelAdmin, self).queryset(request)
            return qs.select_related()
    
    0 讨论(0)
提交回复
热议问题