GenericForeignKey + model inheritance: uses wrong content type
class Link(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey(ct_field="content_type", fk_field="object_id")
class Base(models.Model):
links = GenericRelation(Link)
class Sub(Base): pass
>>> link = Link()
>>> link.content_type = sub_instance
>>> link.save() # saves with "sub" content type
>>> sub_instance.links.all() # queries with "base" content type
[]
>>> sub_instance.base_ptr.links.all() # queries with "base" content type
[]
The expected result would contain the Link object just created, presumably in both cases, but at least in the first. Either GenericForeignKey should use the parent class content type, or GenericRelation uses the content type of the model it is accessed through.
There may be additional complexities involved when using multiple model inheritance, but I can't quite wrap my head around those so far.
Change History
(5)
milestone: |
→ 1.1
|
Triage Stage: |
Unreviewed → Accepted
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
I've been bitten by this one too...