[Django] #36365: Admin filter_horziontal with formfield_for_manytomany hides existing records

12 views
Skip to first unread message

Django

unread,
May 3, 2025, 4:23:04 PMMay 3
to django-...@googlegroups.com
#36365: Admin filter_horziontal with formfield_for_manytomany hides existing
records
-------------------------------------+-------------------------------------
Reporter: Ramon | Type: Bug
Status: new | Component:
| contrib.admin
Version: 4.2 | Severity: Normal
Keywords: admin, | Triage Stage:
filter_horizontal | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
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.
Database: club, member, team.
member and team belong to one club
team consists of members
member can transfer to another club, causing the issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/36365>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 3, 2025, 4:23:22 PMMay 3
to django-...@googlegroups.com
#36365: Admin filter_horziontal with formfield_for_manytomany hides existing
records
-------------------------------------+-------------------------------------
Reporter: Ramon | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: admin, | Triage Stage:
filter_horizontal | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ramon):

* Attachment "example.zip" added.

Django

unread,
May 3, 2025, 4:24:31 PMMay 3
to django-...@googlegroups.com
#36365: Admin filter_horziontal with formfield_for_manytomany hides existing
records
-------------------------------------+-------------------------------------
Reporter: Ramon | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: admin, | Triage Stage:
filter_horizontal | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ramon):

* Attachment "screenshot_admin_1.png" added.

Django

unread,
May 3, 2025, 4:24:49 PMMay 3
to django-...@googlegroups.com
#36365: Admin filter_horziontal with formfield_for_manytomany hides existing
records
-------------------------------------+-------------------------------------
Reporter: Ramon | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: admin, | Triage Stage:
filter_horizontal | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ramon):

* Attachment "screenshot_admin_2.png" added.

Django

unread,
May 3, 2025, 4:25:51 PMMay 3
to django-...@googlegroups.com
#36365: Admin filter_horziontal with formfield_for_manytomany hides existing
records
-------------------------------------+-------------------------------------
Reporter: Ramon | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: admin, | Triage Stage:
filter_horizontal | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Ramon:

Old description:

> 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.
> Database: club, member, team.
> member and team belong to one club
> team consists of members
> member can transfer to another club, causing the issue.

New description:

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.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36365#comment:1>

Django

unread,
May 4, 2025, 2:34:17 AMMay 4
to django-...@googlegroups.com
#36365: Admin filter_horziontal with formfield_for_manytomany hides existing
records
-------------------------------------+-------------------------------------
Reporter: Ramon | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution:
Keywords: admin, | Triage Stage:
filter_horizontal | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Ramon:

Old description:

> 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.

New description:

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.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36365#comment:2>

Django

unread,
May 5, 2025, 5:28:19 PMMay 5
to django-...@googlegroups.com
#36365: Admin filter_horziontal with formfield_for_manytomany hides existing
records
-------------------------------------+-------------------------------------
Reporter: Ramon | Owner: (none)
Type: Bug | Status: closed
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution: invalid
Keywords: admin, | Triage Stage:
filter_horizontal | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* resolution: => invalid
* status: new => closed

Comment:

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 [https://docs.djangoproject.com/en/dev/faq/help
/#how-do-i-do-x-why-doesn-t-y-work-where-can-i-go-to-get-help 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
[https://docs.djangoproject.com/en/dev/internals/contributing/triaging-
tickets/#closing-tickets 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!
--
Ticket URL: <https://code.djangoproject.com/ticket/36365#comment:3>
Reply all
Reply to author
Forward
0 new messages