Category Archives: Programming

Programming

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.

Django snippet: reduce image size during upload

Just a quick python snippet I written today to reduce the image size during upload class PhotoField(forms.FileField, object): def __init__(self, *args, **kwargs): super(PhotoField, self).__init__(*args, **kwargs) self.help_text = “Images over 500kb will be resized to keep under 500kb limit, which may result in some loss of quality” def validate(self,image): if not str(image).split(‘.’)[-1].lower() in [“jpg”,”jpeg”,”png”,”gif”]: raise ValidationError(“File… Read More »

Creating custom log handler that logs to database models in django

I was told to create some kind of logging mechanism to insert logs into database, and make sure it’s generic. So after some thought I decided to mimic the builtin RotatingFileHandler and write a DBHandler. The RotatingFileHandler allows you to specify which file to write to and rotate files, therefore my DBHandler should also allow… Read More »