[Django] #34897: Django's admin UI - `ManyToManyField` with inheritance on the same class -> object shows itself inside the relation

6 views
Skip to first unread message

Django

unread,
Oct 10, 2023, 9:18:22 PM10/10/23
to django-...@googlegroups.com
#34897: Django's admin UI - `ManyToManyField` with inheritance on the same class ->
object shows itself inside the relation
-------------------------------------+-------------------------------------
Reporter: Leon | Owner: nobody
Haffmans |
Type: Bug | Status: new
Component: | Version: 4.2
contrib.admin | Keywords: inheritance,
Severity: Normal | ManyToMany
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 1 |
-------------------------------------+-------------------------------------
Consider a base class `Followable` which is an actual table in the
database. Create a `User` model, which inherits from `Followable` but also
contains a `ManyToManyField` relating to `Followable` called `follows`.

Now, when using Django's admin panel, a user will (wrongly) always show up
in `follows` as reference to itself. This reference has nothing to do with
the database, there is no entry in the relation table.

This should serve as a little reproducable example:

{{{
class Followable(models.Model):
# This is necessary to prevent doubled id name in `User`
followable_id = models.BigAutoField(primary_key=True)

class User(Followable):
alias = models.CharField(max_length=32)
follows = models.ManyToManyField(Followable, blank=True,
related_name="followed_by")

User(alias="foo_user").save()
user = User.objects.get(alias="foo_user")
assert len(user.follows) == 0
}}}

If this is a known issue, I apologize. I wasn't able to find posts
addressing this issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/34897>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 10, 2023, 9:30:04 PM10/10/23
to django-...@googlegroups.com
#34897: Django's admin UI - `ManyToManyField` with inheritance on the same class ->
object shows itself inside the relation
-------------------------------------+-------------------------------------
Reporter: Leon Haffmans | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 4.2
Severity: Normal | Resolution: invalid
Keywords: inheritance, | Triage Stage:
ManyToMany | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Leon Haffmans):

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


Comment:

I'm sorry, I didn't understand the admin UI properly. You can just ignore
this.

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

Reply all
Reply to author
Forward
0 new messages