开发者

Django: model testing setUp get test record insert id

I'm new on testing Django applications but I feel there should be some sort of internal framework method to retrieve last insert id.

How开发者_如何学编程 to get last insert id?

Sultan


There is no specific way of getting the last insert id, but when inserting you get the entire object including the id.

new_instance = models.SomeModel(foo='something', bar='something else')
new_instance.save()
print new_instance.pk

new_instance = models.SomeModel.objects.create(foo='something', bar='something else')
print new_instance.pk
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜