''Say we have a non-abstract superclass and a subclass, and we add a GR
relationship to the subclass:''
{{{
class Order(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()
status = models.CharField(max_length=10, default='ordered')
class Media(models.Model):
order = generic.GenericRelation(Order)
class Photo(Media):
title = models.CharField()
Photo.objects.filter(order__status='ordered').count()
--> doesn't break, but always returns 0.
}}}
''The basic problem is that when the Order object is created Django
inserts it into the DB using the content_type of Photo, but when the
select is run Django realizes Order actually lives in Media and tries to
use that content_type. So the inserts all "work", but the count() never
finds them. It's a mismatch between the content_type_id when it runs the
insert and select.
After digging through django/config/contenttypes/generic.py a bit I feel
like the correct answer is to change the inserts to use the content_type
of the class that actually contains the m2m relationship. (Media, in this
case).''
There is a proposed fix attached to that ticket.
--
Ticket URL: <https://code.djangoproject.com/ticket/19722>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => ramiro
* status: new => assigned
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/19722#comment:1>
* has_patch: 0 => 1
Comment:
This seems to be fixed in Django 1.6 as of
c9a96075fa02b6d52bec748ffdfb413688a15774.
[https://github.com/django/django/pull/5412 PR] to add a regression test.
--
Ticket URL: <https://code.djangoproject.com/ticket/19722#comment:2>
* stage: Accepted => Ready for checkin
Comment:
Regression test case LGTM.
--
Ticket URL: <https://code.djangoproject.com/ticket/19722#comment:3>
Comment (by Tim Graham <timograham@…>):
In [changeset:"4a7b58210defea33a428b748ccbc97ae8fd49838" 4a7b582]:
{{{
#!CommitTicketReference repository=""
revision="4a7b58210defea33a428b748ccbc97ae8fd49838"
Refs #19722 -- Added a test for querying generic relations of a parent
class.
Fixed in c9a96075fa02b6d52bec748ffdfb413688a15774.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19722#comment:4>
* status: assigned => closed
* resolution: => fixed
--
Ticket URL: <https://code.djangoproject.com/ticket/19722#comment:5>