On Thu, Apr 10, 2014 at 8:29 AM, Conrad Rowlands
<[email protected]> wrote:
> Why is this and how can I stop this behaviour but still bring back the
> Manufacturer Details. I expected instead the first query to load all of the
> data.


override the get_collection() method in your View (or ViewSet) to add
a select_related().

for example, something like this (untested!): add this mixin to your
View and optionally set the related_fields:

class SelectRelatedMixin(object):
    related_fields = ()
    def get_queryset(self):
        return super(SelectRelatedMixin,
self).get_queryset().select_related(*self.related_fields)


class ManufacturerModelViewSet(SelectRelatedMixin, viewsets.ModelViewSet):
    related_fields = ('manufacturer',)
    ..... the rest of your viewset

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/CAFkDaoTLYS9DwdfTtGBBOVHgSyRyU1tqnXs6qui5aYUUzEcKCw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to