Mil*_*ano 9 python sql django django-admin
我有一个模型Domain,并将其ForeignKey语言模型设置list_editable为ModelAdmin.
问题是它会引起大量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')
Run Code Online (Sandbox Code Playgroud)
它仍然SQL对 every 执行查询Domain以获取所有Language对象。
如何让它一次获取所有Domains?
Django-cachalot is especially efficient in the Django administration website since it\xe2\x80\x99s unfortunately badly optimised (use foreign keys in list_editable if you need to be convinced).
https://django-cachalot.readthedocs.io/en/latest/introduction.html
\n| 归档时间: |
|
| 查看次数: |
453 次 |
| 最近记录: |