How to get the ID of the record just saved

前端 未结 6 558
终归单人心
终归单人心 2020-12-24 04:36

I\'m using Django 1.3 for one of my projects and I need to get the ID of a record just saved in the database.

I have something like the code below to save a record i

6条回答
  •  悲哀的现实
    2020-12-24 04:52

    Remove save() and get pk directly:

    n = MyData.objects.create(record_title=title, record_content=content)
    n.pk
    

提交回复
热议问题