Hi Javier, Sorry for not being a bit clearer. Basically I am making a URL call to return all of the models with a given manufacturer. So the first SQL statement generated is returning all of the ManufacturerModel AND (because of the select related) all of the Manufacturers too in one query. The second query is requesting ALL of the manufacturers regardless of the filter I described. Now The reason that this second call is being made is because of my ManufacturerViewSet:- Code details below
class ManufacturerViewSet(viewsets.ModelViewSet): queryset=Manufacturer.objects.all() serializer_class = ManufacturerSerialiser filter_class = ManufacturerFilter class ManufacturerModelViewSet( viewsets.ModelViewSet): model=ManufacturerModel serializer_class=ManufacturerModelSerialiser filter_class=ManufacturerModelFilter def get_queryset(self): queryset = ManufacturerModel.objects.all().select_related() return queryset As you can see the queryset is loading all from the database.... What I would prefer to be able to do is to share the first queryset from the ManufacturerModelViewSet (which should have all of the correct fields) with the ManufacturerViewSet. I'm guessing this could be achieved by overriding get_queryset in my ManufacturerViewSet though I don't know what to do from there? On Friday, 11 April 2014 14:17:11 UTC+1, Javier Guerra wrote: > > On Fri, Apr 11, 2014 at 3:51 AM, Conrad Rowlands > <conradj...@googlemail.com <javascript:>> wrote: > > I would still be keen to know if there is any know method that would > allow > > me to load this data using only the 1 queries bringing in all of the > related > > fields in the original query. > > > what's the first query about? probably it's part of the authorization > process, so it might not be appropriate to reduce to just one query. > > in any case, the exact number of queries is irrelevant. the important > thing is to keep it constant for any data size. > > for example, a slightly complex task could easily need 10 queries but > the final throughput you get from the system would be almost the same > if it's 10 queries or just 1, as long as it's not (n+1) as you had > before. > > of course, you still have to be sure the indexes are optimal to keep > each query nice and tight! > > -- > Javier > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5040ee6b-2984-43fc-833b-cdd2efbf5a73%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.