我想在 django admin 中插入后创建一个像记录 ID 这样的目录,我该如何以及在哪里可以做到这一点。
我在 save_model 中尝试,但它不起作用,Gallery.ID 返回无
模型:
class Gallery(models.Model):
title = models.CharField(max_length=250)
added = models.DateTimeField()
active = models.BooleanField()
def __unicode__(self):
return self.title
和 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()