小编bps*_*ott的帖子

Django一旦被访问就会缓存相关的ForeignKey和ManyToManyField字段吗?

鉴于以下模型,Django是否在第一次访问后缓存相关对象?

class Post(models.Model):
    authors = models.ManyToManyField(User)
    category = models.ForeignKey(Category)
Run Code Online (Sandbox Code Playgroud)

例如:

post = Post.objects.get(id=1)

# as i understand this hits the database
authors1 = post.authors.all()
# does this his the database again?
authors2 = post.authors.all()

# as i understand this hits the database
category1 = post.category
# does this hit the database again?
category2 = post.category
Run Code Online (Sandbox Code Playgroud)

注意:目前正在使用Django 1.3,但很高兴知道其他版本中可用的内容.

python django django-models

10
推荐指数
1
解决办法
3854
查看次数

标签 统计

django ×1

django-models ×1

python ×1