thread locals and user object in django

There is an interesting scenario regarding automation of routines related to model.

I want make my model in such a way that, everytime it is modified by some user, it should automatically set “modified by” field with current logged in user.
first step is to override “save” method in model, do update fields as you require and call super class save method.
but the question is, how model can access logged in user object, there is no request object wright?
there is a way with thread locals to deal with this kind of situation, click on following link
thread local and user objct in django models

mysql for python 2.6

if you want to use mysql with python, apart from standard installations, you also need a small integrator called mysql for python. Its a python based module to make sure that all communications with mysql from python code to look and behave similar rest of python style apis.

if you are on windows with python 2.5, you can get it from following link
mysql for python

However, for python 2.6, above installation is not working. follow below link
mysql for python 2.6

dir command in Python

There is a quite useful command in python to introspect a particular object or module.
Pass any object or module to dir function, which is a built-in function. Yes, you can access it from Python interpreter.

>>> a = []
>>> dir(a)

['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']

Quite simple, yet powerful.

also, try this interesting stuff, philosophy of python on “this”
import this

Regular Expressions – Python

While searching for python based parser implementations, for my next personal project, visited following websites about regular expressions, thought useful to others also.

1. Python official documentation about RE

2. Dive into Python – (Basic cookbook)

DJango fixtures

One of the important feature from DJango is fixture generation and consumption.

Fixture is nothing but searialized data in file with proper file naming. Well, it by default recognizes some serialization formats. ex: xml, json etc. Usally file names goes like this: MyFixture.json.

DJango tries to learn data format from file extension.
Generating fixtures from DJango is pretty easy dumpdata

Above command results serialized data of all models of your all apps under project. Ofcourse, there are couple of options to fine tune your command to exclude some apps, to mention format of serialization etc. help dumpdata

issue above command to get full details of available options from your DJango project path.