debug_toolbar报告的重复查询

时间:2015-09-18 22:52:03

标签: python django django-debug-toolbar

我最近在我的应用程序中安装了debug_toolbar,并报告了查询正在运行两次。

debug_toolbar报告重复的数据库查询。

quartz

来自views.py的代码段是:

SET SQL_AUTO_IS_NULL = 0
Duplicated 2 times.

/Users/siquick/Django/soundshelter/soundshelterapp/views.py in release(128)
  genre = [release['genre'] for release in context_dict['release']]

造成这种重复的原因是什么?我知道它是由这一行 release_list = Releases.objects.filter(id=release_id).values('all_artists','label_no_country','id','title','genre').annotate(cnt=Count('chartsextended'))[:1] context_dict['release'] = release_list genre = [release['genre'] for release in context_dict['release']] label_no_country = [release['label_no_country'] for release in context_dict['release']] all_artists = [release['all_artists'] for release in context_dict['release']] title = [release['title'] for release in context_dict['release']] 引起的,但不确定为什么会发生这种情况。

1 个答案:

答案 0 :(得分:2)

之所以发生这种情况,是因为,我猜,“流派”也是一种模式。

您应该使用select_related('genre')才能获取它们一次。 https://docs.djangoproject.com/en/1.9/ref/models/querysets/#select-related