Created
October 29, 2010 12:50
-
-
Save dchaplinsky/653494 to your computer and use it in GitHub Desktop.
Patch for django ORM to display all simple SELECT requests which makes lookup by one key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models.query import QuerySet | |
old_get = QuerySet.get | |
def new_get(self, *args, **kwargs): | |
if len(kwargs) == 1: | |
for field_name in kwargs: | |
if "__" in field_name: | |
field_name, kind = field_name.split("__") | |
if kind != 'exact': | |
continue | |
if field_name == 'pk': | |
field = self.model._meta.pk | |
else: | |
field = self.model._meta.get_field(field_name) | |
if field.db_index or field.primary_key: | |
print "%sselect from %s by indexed field %s%s" % \ | |
('\033[31m', self.model._meta.db_table, field_name, '\033[0m',) | |
return old_get(self, *args, **kwargs) | |
QuerySet.get = new_get |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment