Opened 6 years ago
Closed 6 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 |
Description
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:
models.py:
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)
admin.py:
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 db_field.name == 'user': kwargs['initial'] = request.user.id kwargs['widget'] = widgets.HiddenInput return super().formfield_for_foreignkey(db_field, request, **kwargs) @admin.register(Parent) class ParentAdmin(admin.ModelAdmin): inlines = [ChildInline]
Steps to reproduce the bug:
- Open the Django admin.
- 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 by , 6 years ago
Owner: | changed from | to
---|
follow-up: 3 comment:2 by , 6 years ago
comment:3 by , 6 years ago
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 by , 6 years ago
Triage Stage: | Unreviewed → Accepted |
---|
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 by , 6 years ago
Yeah, it looks like it has been there for at least since the admin was re-factored in 1.0.
Are you able to determine if this is a regression (maybe by bisecting)?