Opened 4 months ago

Closed 4 months ago

#36365 closed Bug (invalid)

Admin filter_horziontal with formfield_for_manytomany hides existing records

Reported by: Ramon Owned by:
Component: contrib.admin Version: 4.2
Severity: Normal Keywords: admin, filter_horizontal
Cc: Ramon Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ramon)

Django admin filter_horizontal for manytomany field should show all existing relations in the right-side pane, even when formfield_for_manytomany updates the queryset to not show that relation in the left-side pane. It is misleading to the user to not show the existing relation.

Working example attached (example.zip).
Database: club, member, team.
member and team belong to one club
team consists of members
member can transfer to another club, causing the issue.

admin.py contains two versions of the team admin model (1 and 2)
Screenshots for each admin model usage are attached.
In screenshot 2 the record Member (5) is not shown in the right-side pane, while it is present in the database.

Attachments (3)

example.zip (7.5 KB ) - added by Ramon 4 months ago.
screenshot_admin_1.png (74.6 KB ) - added by Ramon 4 months ago.
screenshot_admin_2.png (75.0 KB ) - added by Ramon 4 months ago.

Download all attachments as: .zip

Change History (6)

by Ramon, 4 months ago

Attachment: example.zip added

by Ramon, 4 months ago

Attachment: screenshot_admin_1.png added

by Ramon, 4 months ago

Attachment: screenshot_admin_2.png added

comment:1 by Ramon, 4 months ago

Description: modified (diff)

comment:2 by Ramon, 4 months ago

Description: modified (diff)

comment:3 by Natalia Bidart, 4 months ago

Resolution: invalid
Status: newclosed

Hello Ramon, thank you for taking the time to create this ticket. I have reviewed the attached sample project (thanks for including that) and also the screenshots. Below a few notes:

  1. Django 4.2 is on extended support, meaning that only security fixes and data loss bugs will be fixed in that version. So any future information would ideally be based on/tested in newer a Django version (ideally 5.2 or main).
  2. I don't understand the issue since the custom logic that you added in formfield_for_manytomany is explicitely leaving Member object (5) (name Member 21) outside the queryset. Why would this member, that belongs to another club (Club 2), be listed in this page where your custom model admin is explicitly excluding those entries?

Because of the above, this report seems better suited to be a support request. The best place to get answers to your issue is using any of the user support channels from this link.

Since the goal of this issue tracker is to track issues about Django itself, and your issue seems, at first, to be located in your custom code, I'll be closing this ticket as invalid following the ticket triaging process. If, after debugging, you find out that this is indeed a bug in Django, please re-open with the specific details.

Thank you!

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