Follow Join

Stay away from django-nonrel :-| Oct 16, 2012

If you're thinking to use https://github.com/django-nonrel to work with MongoDB, well, please don't, atleast for a while :-|

why, do you ask ?

I went for it. MongoDB. Non Relational Databases. Awesome ! It really is awesome, except that its query evaluation is BROKEN.

in django ORM, it works pretty well with Model.objects.filter(), but it works exactly opposite if you use Model.objects.exclude() !

In my use case I needed to create quite a few Q objects and AND/OR them according to some conditions. I was AND'ing.

I thought of a dirty hack. I can invert my logic and get the thing done for now. that means OR'ing and reverting signs. So it will fail according to other platforms but I can just get done with this thing. Guess what, Multiple OR's are still not supported :-| There is a ticket for this on github. #140 I think.

So I can't get the thing done by any means, except, scrap django-nonrel :-|

Code rewrite. Why ? because I used List and Dict field provided by djangotoolbox, Need to change them in relationships and change code accordingly :-|

I did some quick checks to find this out. Made exactly similar app [ Contacts ] in django 1.3 and django-nonrel 1.3. dumped same data and fired same queries. Here's a screenshot of results. On Left its sqlite3, on right its MongoDB. May not make sense because you don't know the whole set of data but compare the output of exclude() according to Q object given above. If you know django, you should get whats wrong.

Screenshot

Session error: Can't pickle Oct 7, 2012

If you are getting error like Can't pickle <type 'mod_wsgi.Input'>: attribute lookup mod_wsgi.Input failed , you are probably doing something wrong with request+session.

In my case the object I was storing in session had reference to request object saved inside it.

Caching QuerySet to improve performance Sep 27, 2012

This is right from the docs :

Caching and QuerySets¶ Each QuerySet contains a cache, to minimize database access. It's important to understand how it works, in order to write the most efficient code.

In a newly created QuerySet, the cache is empty. The first time a QuerySet is evaluated -- and, hence, a database query happens -- Django saves the query results in the QuerySet's cache and returns the results that have been explicitly requested (e.g., the next element, if the QuerySet is being iterated over). Subsequent evaluations of the QuerySet reuse the cached results.

Keep this caching behavior in mind, because it may bite you if you don't use your QuerySets correctly. For example, the following will create two QuerySets, evaluate them, and throw them away:

>>> print([e.headline for e in Entry.objects.all()])
>>> print([e.pub_date for e in Entry.objects.all()])

That means the same database query will be executed twice, effectively doubling your database load. Also, there's a possibility the two lists may not include the same database records, because an Entry may have been added or deleted in the split second between the two requests.

To avoid this problem, simply save the QuerySet and reuse it:

>>> queryset = Entry.objects.all()
>>> print([p.headline for p in queryset]) # Evaluate the query set.
>>> print([p.pub_date for p in queryset]) # Re-use the cache from the evaluation.

Also See These :-
https://docs.djangoproject.com/en/dev/topics/db/optimization/#understand-queryset-evaluation http://stackoverflow.com/questions/4631865/caching-query-results-in-django

jquery data tables Sep 23, 2012

just finished with django + jquery datatables. used these resources. Need to put all of them together in one place. but still its not that hard with current ones.

http://www.datatables.net/

http://www.datatables.net/usage/server-side

demo app - https://www.assembla.com/spaces/datatables_demo/wiki

datatables + bootstrap 2 goes hand in hand too :-) http://datatables.net/blog/Twitter_Bootstrap_2

session not saving ? Sep 22, 2012

It may happen that django is not noticing your modification to session. It happened to me just now while I was appending to a list there.

Either put SESSION_SAVE_EVERY_REQUEST=True in settings.py

or set request.session.modified = True after modifying something in session that you suppose django may not notice.

django recommends former way.