Opened 5 months ago
Last modified 2 months ago
#36336 assigned Bug
Incorrect size of first autocomple in Inlines with "collapsed" class — at Version 1
Reported by: | Michał Pokusa | Owned by: | |
---|---|---|---|
Component: | contrib.admin | Version: | 5.1 |
Severity: | Normal | Keywords: | autocomplete collapse size inline |
Cc: | Jan Tumpa, yassershkeir | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | yes |
Description (last modified by )
This error occurs on versions after removing the "collapse.js" and moving to <details> and <summary> tags, mainly Django>=5.1 and in my opinion is purely JS/CSS related and Python independent. This happens using both StackedInline
and TabularInline
.
Tested on Google Chrome, Firefox, Edge, Brave and Safari, but with inconsistnt results, seems like the problems is mainly on desktop, but also on mobile devides when using desktop mode with sidebar open (I know how it sounds, but it might be caused by some element width checking).
Steps to reproduce:
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"] classes = ["collapse"] @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",)