Django | Set the defulat ordering rule for queries in the models

Though we can specify order explicitly in queries like below Posts.objects.order_by(‘published’) it is repetitive and most of the times we will want to order by a particular field. We can specify the order in the models like this

Restrict Django Templates From Deleting Data.

Django allows method calls inside template system. Though this is an useful feature, some of the methods will have side effects. Mostly the ones that alter data. Say, for instance, you have a UserAccount object that has a delete() method. If a template includes something like {{ account.delete }}, where account is a UserAccount object, […]

What do Dollar and Caret ( $ and ^) sign in Django urls mean?

$ and ^ are regular expression characters that have a special meaning: the caret means “require that the pattern matches the start of the string,” and the dollar sign means “require that the pattern matches the end of the string.” For example consider the  following url pattern

Without the dollar sign at the end […]

Right way to break Django code for debugguing

Django traceback is a very helpful tool in Django development. It saves us from the boring tasking of writing print statements to track variables. Traceback doesn’t kick when there is no error.  There may be no coding errors but there is a flaw in our application logic which we want to debug. In such cases […]

Error whil creating super user in django1.4 on MAC

I got the following error while trying to create a super user from shell for django1.4.

This problem was rectified by running this command in terminal before adding the user export LANG=”en_US.UTF-8″ I’m guessing this character encoding problem while running syncdb is the reason for the following error while accessing admin section of django1.4 […]