#31498: GenericRelation's get_internal_type() incorrectly reports
"ManyToManyField".
------------------------------------------------+------------------------
               Reporter:  George Dorn           |          Owner:  nobody
                   Type:  Bug                   |         Status:  new
              Component:  contrib.contenttypes  |        Version:  3.0
               Severity:  Normal                |       Keywords:
           Triage Stage:  Unreviewed            |      Has patch:  0
    Needs documentation:  0                     |    Needs tests:  0
Patch needs improvement:  0                     |  Easy pickings:  0
                  UI/UX:  0                     |
------------------------------------------------+------------------------
 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31498>
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/053.5d2cd3ca4ca17f657c67cf0b1e4228aa%40djangoproject.com.

Reply via email to