samedi 29 novembre 2014

Django prefetch_related id seulement - Stack Overflow


I'm trying to optimise my queries but prefetch_related insists on joining the tables and selecting all the fields even though I only need the list of ids from the relations table.


queries


You can ignore the 4th query. It's not related to the question.


Related Code:


class Contact(models.Model):
...
Groups = models.ManyToManyField(ContactGroup, related_name='contacts')
...

queryset = Contact.objects.all().prefetch_related('Groups')


I'm trying to optimise my queries but prefetch_related insists on joining the tables and selecting all the fields even though I only need the list of ids from the relations table.


queries


You can ignore the 4th query. It's not related to the question.


Related Code:


class Contact(models.Model):
...
Groups = models.ManyToManyField(ContactGroup, related_name='contacts')
...

queryset = Contact.objects.all().prefetch_related('Groups')

0 commentaires:

Enregistrer un commentaire