Comment (by David Pratten):
Thanks. Sounds like a good outcome.
--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Mariusz Felisiak):
Replying to [comment:3 David Pratten]:
> Thanks. Sounds like a good outcome.
Would you like to prepare a patch via GitHub PR? The following should
work:
{{{#!diff
diff --git a/django/contrib/admin/checks.py
b/django/contrib/admin/checks.py
index 27537d9614..a844b3f16f 100644
--- a/django/contrib/admin/checks.py
+++ b/django/contrib/admin/checks.py
@@ -533,6 +533,16 @@ class BaseModelAdminChecks:
return must_be(
"a many-to-many field", option=label, obj=obj,
id="admin.E020"
)
+ elif not field.remote_field.through._meta.auto_created:
+ return [
+ checks.Error(
+ f"The value of '{label}' cannot include the
ManyToManyField "
+ f"'{field_name}', because that field manually
specifies a "
+ f"relationship model.",
+ obj=obj.__class__,
+ id="admin.E013",
+ )
+ ]
else:
return []
}}}
Tests and [https://docs.djangoproject.com/en/stable/ref/checks/#admin docs
changes] (in the `admin.E013` description) are also required.
--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:4>
* owner: nobody => David Pratten
* status: new => assigned
Comment:
Ok I'll take this up.
--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:5>
Comment (by David Pratten):
Replying to [comment:4 Mariusz Felisiak]:
I'm happy to work through this, but it won't be quick.
- Are we redefining {{{admin.E013}}} there seems to already be a
description of this error?
- Could you direct me to an explanation of where the documentation for the
errors is held and how it is updated?
- Could you direct me to an explanation of how to add a test case?
Thanks
--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:6>
Comment (by Mariusz Felisiak):
Replying to [comment:6 David Pratten]:
> - Are we redefining {{{admin.E013}}} there seems to already be a
description of this error?
> - Could you direct me to an explanation of where the documentation for
the errors is held and how it is updated?
We want to add `filter_vertical[n]` and `filter_horizontal[n]` to the
existing error `admin.E013` that is documented in
[https://github.com/django/django/blob/8eef22dfed2d53df0da10c0090d9cb04f66efb15/docs/ref/checks.txt#L637-L639
docs/ref/checks.txt], so we need to update the message in docs to the:
''"`fields[n]/filter_horizontal[n]/filter_vertical[n]/fieldsets[n][m]`
cannot include the `ManyToManyField` `<field name>`, because that field
manually specifies a relationship model."''
Docs are wrapped at 79 chars.
> - Could you direct me to an explanation of how to add a test case?
I would add test methods to the
`tests.modeladmin.test_checks.FilterHorizontalCheckTests` and
`tests.modeladmin.test_checks.FilterVerticalCheckTests`.
--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:7>
* cc: Natalia Bidart (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:8>
Comment (by Natalia Bidart):
Hello David, would you have time to work on this? Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:9>
* owner: David Pratten => Hrushikesh Vaidya
Comment:
Since David seems to be busy, I'll try to take this up.
--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:10>
Comment (by Hrushikesh Vaidya):
[https://github.com/django/django/pull/16983 PR] ready for review
--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:11>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:12>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:13>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"107865780aa44914e21d27fdf4ca269bc61c7f01" 10786578]:
{{{
#!CommitTicketReference repository=""
revision="107865780aa44914e21d27fdf4ca269bc61c7f01"
Fixed #34345 -- Added system check for ManyToManyFields with intermediate
tables in ModelAdmin.filter_horizontal/vertical.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34345#comment:14>