1 | | Thanks for the report, however `GenericForeignKey` doesn't support `prefetch_related()`, from the same reason it doesn't not support also `filter()`, `exclude()`, etc. Please see [https://docs.djangoproject.com/en/2.2/ref/contrib/contenttypes/#generic-relations documentation]: |
2 | | {{{ |
3 | | Due to the way GenericForeignKey is implemented, you cannot use such fields directly with filters (filter() and exclude(), for example) via the database API. Because a GenericForeignKey isn’t a normal field object, these examples will not work: |
4 | | ... |
5 | | }}} |
6 | | |
7 | | Provided example works as expected with UUID PK, e.g.: |
8 | | {{{ |
9 | | >>> for bar in Bar.objects.all(): |
10 | | ... print(bar, bar.foo) |
11 | | Bar object (4) Foo object (e6bdfd5e-51a8-49c7-9a7a-998452fad6aa) |
12 | | }}} |
| 1 | Thanks for the report, ~~however `GenericForeignKey` doesn't support `prefetch_related()`, from the same reason it doesn't not support also `filter()`, `exclude()`, etc. Please see [https://docs.djangoproject.com/en/2.2/ref/contrib/contenttypes/#generic-relations documentation].~~ |