开发者

Django: model testing setUp get test record insert id

开发者 https://www.devze.com 2023-01-30 18:13 出处:网络
I\'m new on testing Django applications but I feel there should be some sort of internal framework method to retrieve last 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

精彩评论

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

关注公众号