Archive for the 'django' Category


Django Tip: No leading slash for upload_to for FileField and ImageField

This is a common mistake. When defining a FileField or an ImageField, you need to specify
where the files are stored. This is done by specifying a relative path in the upload_to
argument. Django will then store your files in a subdirectory as named, under the MEDIA_ROOT
directory. But, don’t put a leading slash in the relative path. […]

Django Tip: Outputting list of items separated by commas, but only if it has more than one item

How many times do you need to do this? You have a list of things to output. The list can be empty, has one element, or more. You want to separate each items with a separator for readability. What do you do?
1. The simple but not reader friendly way:
toppings = [ ‘cheese’,’tomatos’,’pineapple’ ]
or toppings = […]

Emacs for OS X Leopard

I have been using the text mode emacs up to now. On Windows (yikes!) I uses the xemacs with windows extension, which is pretty nice. Quick googling found me Carbon Emacs. It has been updated, universal binary and Leopard. Highly recommended !

gettext on Leopard for Django Internationalization

I started working on one of my internationalized applications on the new Mac. I realized I did not install “gettext”, which is required by the make-messages and compile-messages scripts. I want to avoid installing things into OS X if I can. Then I found the easy way out:
1. Install poedit for os x. I need […]

Django on Leopard

Part of the reason I was waiting to switch from using Windows XP (gasp) as my Django development platform to OS X is that it is actually easier to install the platform on XP. Windows does not come with any of the tools, so it was a matter of installing the version that I need. […]

Django 0.96 Internationalization

I am trying out Django’s i18n support and found a few issues. This only applies if you are using newforms and Django 0.96.
Order of Middleware
First, the order of the middleware is important. It is defined in the documentation, but I missed it the first time around. You have to put the localeMiddleware after SessionMiddleware:
MIDDLEWARE_CLASSES = […]

Using pytextile in Django - problem with unicode

I am coverting a J2EE application over to django. The existing app uses Textile as a simple markup for user text input. After installing pytextile (which is under ownership change at the moment), I found a problem using it:
The “textile” filter works for strings and strings retrieved from my database, but when I try to […]

The Importance of the initial argument in Django newforms library

I like Django a lot. In fact I am in the middle of converting a large J2EE application to Django. Sometimes I run into a problem using it, and knowing Django, I know there is a good solution. To find the solution however, sometimes require very careful reading of the documentation.
Case in point. The solution […]

psycopg2 broken for 64 bit ubuntu

I want to test out amd64 bit ubuntu. Django keeps failing on syncdb. Turned out the python Postgresql library, psycopg2 is “severely broken” in the 64bit packaging. You will get a segment fault when trying to run the simplest thing like syncdb on an empty system if you are using postgresql. Oh well, for now, […]

Django dumpdata does not work with numeric fields

I try to dump my database in Postgres to json so that I can load it into my test system. Executing manage.py dumpdata gives me an error:
Unable to serialize database: Decimal(\”349.00\”) is not JSON serializable

Some googling finds ticket number 3324, a problem with the serializer. This is patched in the development tree already. Since I […]