标签:bsp tle try pytho auto 索引 imp nbsp 设置
创建对象的时候,尽可能使用bulk_create()来减少SQL查询的数量。此方法以高效的方式(通常只有1个查询,无论有多少对象)将提供的对象列表插入到数据库中:,例如:
Entry.objects.bulk_create([ Entry(headline=‘This is a test‘), Entry(headline=‘This is only a test‘), ])
优于:
Entry.objects.create(headline=‘This is a test‘) Entry.objects.create(headline=‘This is only a test‘)
save()
方法,并且不会发送pre_save
和post_save
信号。AutoField
,则不会像save()
那样检索并设置主键属性,除非数据库后端支持(当前是PostgreSQL)。这也可以用在ManyToManyField中,所以:
my_band.members.add(me, my_friend)
优于
my_band.members.add(me)
my_band.members.add(my_friend)
标签:bsp tle try pytho auto 索引 imp nbsp 设置
原文地址:http://www.cnblogs.com/richiewlq/p/7739727.html