django createview how to get the object that is created

人走茶凉 提交于 2019-11-28 20:12:08
mpaolini

maybe you could use get_success_url() method (see reference)

In this case, it'd be something like:

def get_success_url(self):
    return reverse('offerta_create',args=(self.object.id,))
Chirael

Please see the accepted answer on Why doesn't self.object in a CreateView have an id after saving to the database? - once I removed the "id" fields from my models, and let Django default to its own id AutoField on each model as recommended in that answer, self.object.id worked fine in my CreateView.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!