#31498: GenericRelation's get_internal_type() incorrectly reports
"ManyToManyField".
-------------------------------------+-------------------------------------
Reporter: George Dorn | Owner: nobody
Type: Bug | Status: new
Component: | Version: 3.0
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by George Dorn:
Old description:
> I have two models, one containing a GFK to the other (and presumably
> others models).
>
> {{{
> #!div style="font-size: 80%"
> Code highlighting:
> {{{#!python
>
> class Example(models.Model):
> text = models.TextField()
> example_gfk = GenericRelation(
> "myapp.ExampleGFK",
> related_query_name="example",
> )
>
> class ExampleGFK(Bulkable):
> text = models.TextField()
> content_type = models.ForeignKey(ContentType,
> on_delete=models.CASCADE)
> object_id = models.PositiveIntegerField()
> content = GenericForeignKey("content_type", "object_id")
> }}}
> }}}
>
> When I inspect
> Example._meta.get_field('example_gfk').get_internal_type(), it reports
> back a ManyToManyField. This can't be right, though; as a reverse
> relationship, it should be a ManyToOneRel; an ExampleGFK can't be related
> to more than one Example object.
>
> Perhaps there's a solid reason for this that eludes me, like it tricks
> some part of the admin or other part of the ORM to behave correctly. If
> so, at the very least a note in the documentation or a docstring in the
> code could clarify that reason.
New description:
I have two models, one containing a GFK to the other (and presumably
others models).
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
class Example(models.Model):
text = models.TextField()
example_gfk = GenericRelation(
"myapp.ExampleGFK",
related_query_name="example",
)
class ExampleGFK(Bulkable):
text = models.TextField()
content_type = models.ForeignKey(ContentType,
on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content = GenericForeignKey("content_type", "object_id")
}}}
}}}
When I inspect
`Example._meta.get_field('example_gfk').get_internal_type()`, it reports
it is a `ManyToManyField`. This can't be right, though; as a reverse
relationship, it should be a `ManyToOneRel`; a single `ExampleGFK` can't
be related to more than one `Example` object.
Perhaps there's a solid reason for this that eludes me, like it tricks
some part of the admin or other part of the ORM to behave correctly. If
so, at the very least a note in the documentation or a docstring in the
code could clarify that reason.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/31498#comment:1>
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/068.d0d82ca2f03ffc818611ceb6c5d51a56%40djangoproject.com.