Skip to content

Instantly share code, notes, and snippets.

from django.db import connection
class QueryCountMiddleware(object):
def process_response(self, request, response):
duration = 0
for query in connection.queries:
duration += float(query['time'])
print ('%s\n' % query['sql'])
If I remember well, we discussed at some point with you and charettes about
removing the string version (as opposed to callable) of RunPython, if we do it,
it may be better to do it early on in the release cycle.
For some reason MyModel.objects.create() returned an object with pk=None,
I could confirm the object was created with a call to MyModel.objects.all().
I'm not totally sure if it's a bug or a side effect of the fake ORM.
I was bitten quite badly by the fact that custom Manager and custom save()
methods aren't called, https://github.com/django/django/blob/master/docs/topics/migrations.txt#L296-L297
print_tb()
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 249, in remove
del self.data[k]
print_exc()
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 249, in remove
del self.data[k]
KeyError: <weakref at 0x10eeeb310; dead>
print_tb()
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 249, in remove
WeakKeyDictionary
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 260, in remove
del self.data[k]
KeyError: <weakref at 0x10be01a48; dead>
self.data:
{}
k:
<weakref at 0x10be01a48; dead>
# This is an example test settings file for use with the Django test suite.
#
# The 'sqlite3' backend requires only the ENGINE setting (an in-
# memory database will be used). All other backends will require a
# NAME and potentially authentication information. See the
# following section in the docs for more information:
#
# https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/
#
# The different databases that Django supports behave differently in certain
# This is an example test settings file for use with the Django test suite.
#
# The 'sqlite3' backend requires only the ENGINE setting (an in-
# memory database will be used). All other backends will require a
# NAME and potentially authentication information. See the
# following section in the docs for more information:
#
# https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/
#
# The different databases that Django supports behave differently in certain
@loic
loic / -
Created January 26, 2014 08:03
# This is an example test settings file for use with the Django test suite.
#
# The 'sqlite3' backend requires only the ENGINE setting (an in-
# memory database will be used). All other backends will require a
# NAME and potentially authentication information. See the
# following section in the docs for more information:
#
# https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/
#
# The different databases that Django supports behave differently in certain
@loic
loic / gist:8576940
Created January 23, 2014 11:17
Django custom index types.
ML thread:
https://groups.google.com/d/topic/django-developers/hVTLAp_jLzQ/discussion
2013-10-03:
20:15 loic84: akaariai: what's your opinion no the recent ML thread regarding custom index types?
20:18 akaariai: loic84: write the SQL by hand... Or, maybe you could have a VirtualField that just creates indexes for you.
20:20 loic84: akaariai: I've been thinking about integrating PG arrays and JSON support in my projects.
@loic
loic / foo.diff
Last active January 4, 2016 03:19
diff --git a/django/db/models/manager.py b/django/db/models/manager.py
index 4a080e9..fa1e870 100644
--- a/django/db/models/manager.py
+++ b/django/db/models/manager.py
@@ -190,10 +190,9 @@ class BaseManager(six.with_metaclass(RenameManagerMethods)):
# understanding of how this comes into play.
return self.get_queryset()
-Manager = BaseManager.from_queryset(QuerySet, class_name='Manager')
diff --git a/django/db/models/manager.py b/django/db/models/manager.py
index 4a080e9..24f9d95 100644
--- a/django/db/models/manager.py
+++ b/django/db/models/manager.py
@@ -196,6 +196,14 @@ Manager = BaseManager.from_queryset(QuerySet, class_name='Manager')
Manager.__module__ = 'django.db.models.manager'
+class CustomQuerySet(QuerySet):
+ pass