Changes between Initial Version and Version 1 of Ticket #30343, comment 1


Ignore:
Timestamp:
Apr 9, 2019, 11:59:51 PM (6 years ago)
Author:
Mariusz Felisiak

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #30343, comment 1

    initial v1  
    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 }}}
     1Thanks 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].~~
Back to Top