class TaggedItem(models.Model):
tag = models.SlugField()
content_type = models.ForeignKey(ContentType,
on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey("content_type", "object_id")
}}}
{{{
Foo.objects.create()
f = Foo.objects.prefetch_related('tags').last()
a = TaggedItem(tag='tag')
print(f.tags.all())
f.tags.add(a, bulk=False)
print(f.tags.all())
}}}
will give
{{{
<QuerySet []>
<QuerySet []>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29612>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* keywords: GenericForeignKey GenericRelation Prefetch prefetch_related =>
prefetch_related
* version: 2.0 => master
* component: Database layer (models, ORM) => contrib.contenttypes
* stage: Unreviewed => Accepted
Comment:
This is similar to #26706 but for generic relations. The patch can
probably be heavily inspired by d30febb4e59b659e0d279c77f61f936c199a05b2.
--
Ticket URL: <https://code.djangoproject.com/ticket/29612#comment:1>
--
Ticket URL: <https://code.djangoproject.com/ticket/29612#comment:2>
--
Ticket URL: <https://code.djangoproject.com/ticket/29612#comment:3>
* owner: nobody => Tom Forbes
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/29612#comment:4>
* cc: Tom Forbes (added)
Comment:
'Heavily inspired' PR: https://github.com/django/django/pull/10277
--
Ticket URL: <https://code.djangoproject.com/ticket/29612#comment:5>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29612#comment:6>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/29612#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"c02d473781dc2e8699db8edd37cc77f7d43993fc" c02d4737]:
{{{
#!CommitTicketReference repository=""
revision="c02d473781dc2e8699db8edd37cc77f7d43993fc"
Fixed #29612 -- Added GenericRelation prefetch_related() cache
invalidation.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29612#comment:8>