Category Archives: Python

Django admin UnicodeEncodeError

Don’t we all get confused by unicode encoding sometimes? Especially you wouldn’t expect this kind of error to happen in django admin. The problem is actually not in the admin section, the culprit is __unicode__ method in your model. when you have a unicode function like this:

It is actually returning a ASCII string(which… Read More »

Django custom user model in admin, relation “auth_user” does not exist

I have a custom user model as below:

And using the builtin UserAdmin

While editing the user record works fine, but when I add a user, I get the following error

After some digging around and found this https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#custom-users-and-the-built-in-auth-forms The culprit is a function clean_uesrname inside UserCreationForm inside django.contrib.auth.forms.py A few tickets… Read More »

New Zealand Weddings New Website Launch

After a month’s effort we’ve finally released the first phase of the new NZ weddings website. Check it out http://newzealandweddings.co.nz The new site is written in django framework, a lot of functionalities such as the editorial section was ‘borrowed’ from the existing infrastructure which powers the Stoppress and the Idealog websites.

Useful Django Apps – TinyMCE & File Browser

TinyMCE https://code.google.com/p/django-tinymce/ Want to add WYSIWYG editor to your TextFields? This app will sort you right out, basically this app will provide a HTMLField for you to use instead of just plain TextField and it will automatically render a rich text editor for you. It does require some basic configuration, here is a sample config in… Read More »

Useful Django Apps – MPTT

https://github.com/django-mptt/django-mptt MPTT stands for Modified Preorder Tree Traversal, which really means for working with parent child relationships, this app will do some work under hood to make travelling the relationship much quicker and easier, such as some API methods like get_ancestors() etc. Some good usage example would be, category hierarchy, family tree etc.

Useful Django Apps – South

South A data migration tool, what it really means is if you change the data model and want to keep the data in there, you will need this app. At first I thought it’s tedious for early stage development when data isn’t important (why not just syncdb??), but once I realised it’s actually quicker to… Read More »

Installing Python Mysql Adapter On Mac OSX

First download and install mysql for Mac OSX Install virtualenv, create a virtualenv and activate it Pip install mysql-python, and you will see an error “EnvironmentError: mysql_config not found” Find the mysql_config by running “sudo find / -name ‘mysql_config’” Go to your /path to virtualenv/build/mysql-python Edit site.cfg Uncomment this line “#mysql_config = /usr/local/bin/mysql_config” and change… Read More »

Internal SOA data transfer via memcache?

We have been working on a python/django project which is SOA oriented, all sites(systems) are internal and communications are done via http restful api requests. Our setup share the same set of memcache servers to cache data individually on each sub site(system). Often when site A wants data from site B, site A makes a… Read More »

Python performance tips

I came across this python performance tips article this afternoon and found it very interesting. Will definitely start using those tips in my next project.