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
精彩评论