[Django]-Django createview how to get the object that is created

67đź‘Ť

âś…

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

0đź‘Ť

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.

👤Chirael

Leave a comment