Opened 16 months ago

Last modified 3 days ago

#36337 assigned Bug

Broken autocomplete inside Inline after clicking "Add another ..."

Reported by: Michał Pokusa Owned by: Joe Babbitt
Component: contrib.admin Version: dev
Severity: Normal Keywords: autocomplete inline admin
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: yes

Description

This error occurs on versions from 3.2 (or even before, untested) up to latest (5.2 at this time). It seems like it is only JS/CSS related.
Happens with both TabularInline and StackedInline.

Possibly related to #36336.

Tested on Google Chrome, Firefox, Edge and on mobile device.

Steps to reproduce (code below):

  1. Go to change form view (editing existing object, adding new one, doesn't matter)
  2. Click "X" on any inline except last one
  3. Click "Add another ..." once again

https://raw.githubusercontent.com/michalpokusa/static-django-tickets/refs/heads/main/36337/2025-04-19%2012%2016%2000.png

Code:

models.py

from django.db import models


class Restaurant(models.Model):
    name = models.CharField(max_length=100)
    address = models.CharField(max_length=255)

    def __str__(self):
        return self.name


class Order(models.Model):
    restaurant = models.ForeignKey(Restaurant, on_delete=models.CASCADE)
    order_number = models.CharField(max_length=20)
    products = models.ManyToManyField("Product", related_name="orders")

    def __str__(self):
        return f"Order {self.pk} from {self.restaurant.name}"


class Product(models.Model):
    name = models.CharField(max_length=100)
    price = models.DecimalField(max_digits=10, decimal_places=2)

    def __str__(self):
        return f"{self.name} - ${self.price}"

admin.py

from django.contrib import admin

from .models import Restaurant, Order, Product


class OrderInline(admin.StackedInline):
    model = Order
    extra = 3

    fields = ["order_number", "products"]
    autocomplete_fields = ["products"]


@admin.register(Restaurant)
class RestaurantAdmin(admin.ModelAdmin):
    list_display = ("name", "address")
    search_fields = ("name", "address")

    inlines = [OrderInline]


@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
    list_display = ("restaurant", "order_number")


@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    list_display = ("name", "price")

    search_fields = ("name",)

Change History (7)

comment:1 by Natalia Bidart, 16 months ago

Triage Stage: UnreviewedAccepted
Version: 5.2dev

Thank you Michał Pokusa, I was able to reproduce this issue with the provided steps.

comment:2 by Ahmed Nassar, 16 months ago

Owner: set to Ahmed Nassar
Status: newassigned

comment:3 by Joe Babbitt, 3 months ago

Owner: changed from Ahmed Nassar to Joe Babbitt

Hi there Ahmed,
I noticed that this ticket has been owned but inactive for a little over a year. I'm currently working at the PyCon 2026 Django sprint and am going to take a stab at this bug. Hope that's alright!

(Commenting for other sprinters)

comment:4 by Joe Babbitt, 3 months ago

Has patch: set

comment:5 by blighj, 5 days ago

Patch needs improvement: set

comment:6 by Michał Pokusa, 5 days ago

Owner: changed from Joe Babbitt to Michał Pokusa
Patch needs improvement: unset

comment:7 by blighj, 3 days ago

Owner: changed from Michał Pokusa to Joe Babbitt
Patch needs improvement: set

Hi Michael,
Joe waited 3 months for a review, and I only just got round to providing one. It's way too soon to take over the ticket.
Appreciate your willingness to contribute, but I'm afraid this is not the correct ticket to start on, sorry for the wasted effort.

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