I would like after insert in django admin create a directory like a record ID, how and where can I do this.
I try it in to save_model, but it’s not work, Gallery.ID returns None
Model:
class Gallery(models.Model):
title = models.CharField(max_length=250)
added = models.DateTimeField()
active = models.BooleanField()
def __unicode__(self):
return self.title
And AdminModel
class GalleryAdmin(admin.ModelAdmin):
save_on_top = True
list_filter = ('active',)
list_display = ('title','active','added')
ordering = ['-added']
inlines = [ImagesInline]
def save_model(self, request, Gallery, form, change):
if not change:
Gallery.title = str(Gallery.id)
Gallery.save()
Change your
GalleryAdminto this… You need tosave()before theGalleryinstance gets itsid.