#29961: Change-Add-Delete links are visible in tabular inline for foreignkey 
fields
with a HiddenInput widget
-------------------------------------+-------------------------------------
               Reporter:  Hidde      |          Owner:  nobody
  Bultsma                            |
                   Type:  Bug        |         Status:  assigned
              Component:             |        Version:  2.1
  contrib.admin                      |       Keywords:  admin tabular
               Severity:  Normal     |  inline
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  1          |
-------------------------------------+-------------------------------------
 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:
 {{{#!python
 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:
 {{{#!python
 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:**
 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:

 [[Image(https://i.imgur.com/0eHQgmt.png)]]

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29961>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.1459d99d2b1fba4e7a2aeb5c5675f287%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to