django prefetch_related id only

Django 1.7 added Prefetch objects which let you customise the queryset used when prefetching.

In particular, see only().

In this case, you’d want something like:

queryset = Contact.objects.all().prefetch_related(
    Prefetch('Groups', queryset=Group.objects.all().only('id')))

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)