gpt4 book ai didi

python - Django 管理员 : Prefetch choices in list_editable

转载 作者:行者123 更新时间:2023-12-04 13:45:41 27 4
gpt4 key购买 nike

我有一个模型 Domain我把它设置为 ForeignKey语言模型在 list_editableModelAdmin .

问题是它导致了很多 SQL根据django_debug_toolbar查询.我以为我可以使用 select_related 解决它但它没有帮助,因为它只选择实际值,而不是所有选择。

@register(Domain)
class DomainAdmin(admin.ModelAdmin):
list_display = ['id', 'name', 'main_url', 'language', 'max_depth', 'number_of_urls']
list_editable = ['name', 'main_url', 'language', 'max_depth']
list_select_related = ['language']

#def get_queryset(self, request):
# return super(DomainAdmin, self).get_queryset(request).prefetch_related('language')

它仍然执行 SQL查询每个 Domain获取所有 Language对象。

enter image description here

如何让它一次性获取 Domain ?

最佳答案

Django-cachalot is especially efficient in the Django administration website since it’s unfortunately badly optimised (use foreign keys in list_editable if you need to be convinced).
https://django-cachalot.readthedocs.io/en/latest/introduction.html

关于python - Django 管理员 : Prefetch choices in list_editable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48948075/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com