django:有没有办法为内联指定标题

时间:2013-04-17 09:19:16

标签: django django-admin

我有这两位模特管理员:

class SingleImageInline(generic.GenericTabularInline):
  model = Image
  extra = 1
  max_num = 1
  can_delete = False


class SponsorAdmin(admin.ModelAdmin):
    fieldsets = [
      ('Basic Info', {
        'fields': ['name']
      }),
   ]
   list_display = ['name']
   search_fields = ['name']
 inlines = [SingleImageInline, ]

Sponsor有一个名为Image的{​​{1}}字段。具有logo表单的管理表单在其标题中显示SingleImageInline,是否可以将其更改为Images,可能是这样的?

Logo

2 个答案:

答案 0 :(得分:1)

当然可以

class SingleImageInline(generic.GenericTabularInline):
   model = Image
   extra = 1
   max_num = 1
   can_delete = False
   verbose_name = "Logo"
   verbose_name_plural = "Logos"

答案 1 :(得分:0)

你可以给SingleImageInline提供一个verbose_name:

class SingleImageInline(generic.GenericTabularInline):
  model = Image
  extra = 1
  max_num = 1
  can_delete = False
  verbose_name = "logo"
  verbose_name_plural = "logos"

修改

子类SingleImageInline,然后放在verbose_name

class SingleImageInline(generic.GenericTabularInline):
  model = Image
  extra = 1
  max_num = 1
  can_delete = False

class SingleImageInlineOtherName(SingleimageInline):
  verbose_name = "logo"
  verbose_name_plural = "logos" # bit redundant as Django automatically adds 's' to plural names, but it's just for the purpose

class SponsorAdmin(admin.ModelAdmin):
    fieldsets = [
      ('Basic Info', {
        'fields': ['name']
      }),
   ]
   list_display = ['name']
   search_fields = ['name']
 inlines = [SingleImageInlineOtherName, ] # use the subclass here