Django的QuerySet
- values returns one Queryset with dict ,not model instance
- select_related it is useful for tables which has foreign key .it only excute once.
# Hits the database.
e = Entry.objects.get(id=5)
# Hits the database again to get the related Blog object.
b = e.blog
And here’s select_related lookup:
# Hits the database.
e = Entry.objects.select_related('blog').get(id=5)
# Doesn't hit the database, because e.blog has been prepopulated
# in the previous query.
b = e.blog
3.关联对象特殊操作
>>> b = Blog.objects.get(id=1)
>>> e = b.entry_set.create(
... headline='Hello',
... body_text='Hi',
... pub_date=datetime.date(2005, 1, 1)
... )
4.
auto_now无论是你添加还是修改对象,时间为你添加或者修改的时间。
auto_now_add为添加时的时间,更新对象时不会有变动。
--------EOF---------
微信分享/微信扫码阅读
微信分享/微信扫码阅读