Opened 11 years ago

Closed 11 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

Description

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.

# models.py
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)

# forms.py
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

# admin.py
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]
 
admin.site.register(models.FirstModel, FirstAdmin)

Attachments (1)

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

Download all attachments as: .zip

Change History (2)

by yliharma, 11 years ago

Attachment: tabular.png added

TabularInline with hidden field

comment:1 by Claude Paroz, 11 years ago

Resolution: duplicate
Status: newclosed

Fixed in #18263 (will be in 1.7).

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