#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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018b1c502d2d-d04e36c7-6046-421b-9ea2-08557470e56c-000000%40eu-central-1.amazonses.com.