How to omit object name from Django's TabularInline admin view?

后端 未结 6 1879
南方客
南方客 2021-02-01 14:33

I\'m using Django\'s TabularInline admin view to edit category objects related to a main topic object, as shown here:

6条回答
  •  长发绾君心
    2021-02-01 15:26

    I took a slightly different approach. It's a little hackish. This replaces the "original" string with a blank string, so the td for class=original still gets rendered leaving a gap above the edit boxes.

    I like the CSS solution better (I had to use 'padding-top: 5px;' to get the rendering right).

    models.py:

    class Model(model.Model):
      general_questions = models.TextField()
      _hide = False
    
      def __unicode__(self):
        if _hide:
          return ''
    

    admin.py:

    class ModelInline(admin.TabularInline):
        model = Model
        extra = 0
    
    class ModelAdmin(admin.ModelAdmin):
      inlines = [ModelInline, ]
    
      def render_change_form(self, request, context, *args, **kwargs):
        for formset in context['inline_admin_formsets']:
          qs = formset.formset.queryset
            for model_obj in qs:
              model_obj._hide = True
    
      return super(ModelAdmin, self).render_change_form(request, context, *args, **kwargs)
    

提交回复
热议问题