django createview how to get the object that is created django createview how to get the object that is created django django

django createview how to get the object that is created


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,))


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.