tomchristie/django-rest-framework — Issue #81: How about select_related?
Author: ulmus
Created: 2011-10-12 22:50:31+00:00
State: open

I've started profiling my app (long overdue, but I follow the "correct first, fast later" model) and I realized that every foreign key in my resources resulted in an SQL query. With a list of 50 models, each with 4 foreign keys, that adds up to 200 queries!

Normally I'd add select_related to my queryset to optimize this, but I can't seem to make that work in django rest framework, it seems like the serializer generated queries for each foreign key no matter what I do, either that or I'm doing it wrong.

Any suggestions on where to add a select_related command in the django rest framework call chain? I've tried overloading the get-methods in the view but as I've said, it hasnt had any effect

/Jens