Opened 4 years ago

Closed 4 years ago

#21976 closed Bug (duplicate)

Hidden field in TabularInline breaks table layout

Reported by: yliharma Owned by: nobody
Component: contrib.admin Version: 1.6
Severity: Normal Keywords: admin, inlines, hiddenfield
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Defining a hidden field in a ModelForm used within a TabularInline breaks the table layout (see screenshot tabular.png): the hidden field label is not present in the <thead> table tag but there is a corresponding <td> tag containing the actual input, resulting in a different number of table columns which breaks the table completely.

from django.db import models

class FirstModel(models.Model):
    a_field = models.CharField(max_length=10)

class SecondModel(models.Model):
    first_fk = models.ForeignKey(FirstModel)
    b_field = models.CharField(max_length=10)
    c_field = models.CharField(max_length=10)

from django import forms
from dummy.inline_test import models

class SecondForm(forms.ModelForm):
    b_field = forms.CharField(widget=forms.HiddenInput, required=True)

    class Meta:
        model = models.SecondModel

from django.contrib import admin
from dummy.inline_test import models, forms

class SecondAdmin(admin.TabularInline):
    model = models.SecondModel
    form = forms.SecondForm
    extra = 3

class FirstAdmin(admin.ModelAdmin):
    inlines = [SecondAdmin], FirstAdmin)

Attachments (1)

tabular.png (80.4 KB) - added by yliharma 4 years ago.
TabularInline with hidden field

Download all attachments as: .zip

Change History (2)

Changed 4 years ago by yliharma

Attachment: tabular.png added

TabularInline with hidden field

comment:1 Changed 4 years ago by Claude Paroz

Resolution: duplicate
Status: newclosed

Fixed in #18263 (will be in 1.7).

Note: See TracTickets for help on using tickets.
Back to Top