Opened 4 years ago

Closed 4 years ago

#29961 closed Bug (fixed)

Change-Add-Delete links are visible in tabular inline for foreignkey fields with a HiddenInput widget

Reported by: Hidde Bultsma Owned by: Hidde Bultsma
Component: contrib.admin Version: 2.1
Severity: Normal Keywords: admin tabular inline
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes


Setting the widget of an inline foreignkey field to HiddenInput in a TabularInline does not hide the change-add-delete links in the form. This bug does not appear when using a StackInline model admin.

Code sample:

from django.conf import settings
from django.db import models

class Parent(models.Model):
    name = models.CharField(max_length=255)

class Child(models.Model):
    parent = models.ForeignKey(Parent, on_delete=models.CASCADE)
    name = models.CharField(max_length=255)
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

from django.contrib import admin
from django.forms import widgets
from .models import Parent, Child

class ChildInline(admin.TabularInline):
    model = Child

    def formfield_for_foreignkey(self, db_field, request, **kwargs):
        if == 'user':
            kwargs['initial'] =
            kwargs['widget'] = widgets.HiddenInput
        return super().formfield_for_foreignkey(db_field, request, **kwargs)

class ParentAdmin(admin.ModelAdmin):
    inlines = [ChildInline]

Steps to reproduce the bug:

  1. Open the Django admin.
  2. Add or change a parent. The change-add-delete links of the user field in the tabular inline are visible and glitched at the start of each row:

Change History (7)

comment:1 Changed 4 years ago by Hidde Bultsma

Owner: changed from nobody to Hidde Bultsma

comment:2 Changed 4 years ago by Claude Paroz

Are you able to determine if this is a regression (maybe by bisecting)?

comment:3 in reply to:  2 Changed 4 years ago by Hidde Bultsma

Replying to Claude Paroz:

Are you able to determine if this is a regression (maybe by bisecting)?

I will take a look at it.

comment:4 Changed 4 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

I observed the same behavior as far back as I checked (Django 1.8), so if it's a regression it's not a recent one. The extra links come from RelatedFieldWidgetWrapper.

comment:5 Changed 4 years ago by Hidde Bultsma

Yeah, it looks like it has been there for at least since the admin was re-factored in 1.0.

comment:6 Changed 4 years ago by Hidde Bultsma

Has patch: set

comment:7 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 89a2216:

Fixed #29961 -- Made RelatedFieldWidgetWrapper hide related item links if wrapping a hidden widget.

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