annotate() 使事情变得缓慢如爬行一样正常吗?
使用这样的注释:
post_list = j.post_set.all().annotate(num_comments=Count('comment')).order_by('-pub_date')
Run Code Online (Sandbox Code Playgroud)
与不做注释相比,花费的时间是原来的四倍:
post_list = j.post_set.all().order_by('-pub_date')
Run Code Online (Sandbox Code Playgroud)
我还尝试使用 value() 和 defer() ,但这些也没有帮助。将评论数量保留为 Post 表中的字段是唯一真正的选择吗?
顺便说一句,我正在使用MySQL。
我创建了一个virtualenv并在其中安装了Django 1.5
(virtpy33) c:\django_projects>python
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 5, 1, 'final', 0)
>>> ^Z
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个项目并运行了manage.py runserver,但它说它正在运行1.4版本
(virtpy33) c:\django_projects>django-admin.py startproject virtres
(virtpy33) c:\django_projects>cd virtres
(virtpy33) c:\django_projects\virtres>manage.py runserver
Validating models...
0 errors found
Django version 1.4, using settings 'virtres.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Run Code Online (Sandbox Code Playgroud)
我是virtualenv和Django的新手.还有什么我需要做的吗?喜欢编辑settings.py文件或manage.py文件或其他东西?
我的系统(Windows Vista)上的Django 1.4在我的Python27目录下(不是在虚拟环境中),但我设置了virtualenv,所以我可以使用Django 1.5和Python 3.
请帮忙!