[Answered ]-How to in django admn after insert get record ID?

1👍

Change your GalleryAdmin to this… You need to save() before the Gallery instance gets its id.

def save_model(self, request, Gallery, form, change):
    Gallery.save()
    if not change:
        Gallery.title = str(Gallery.id)

1👍

def save_model(self, request, Gallery, form, change):
    if Gallery.id is None:
        Gallery.save()
    if not change:
        Gallery.title = str(Gallery.id)
    Gallery.save()

This will do two save()‘s only the first time.

Leave a comment