Tim Akinbo's Tumblelog RSS

Hi, I'm Tim Akinbo and this is my tumblelog.

Afrigator

My Popularity (by popuri.us)

Archive

Jul
25th
Mon
permalink

Comments (View)

permalink

Comments (View)

Apr
24th
Sun
permalink

MySQL-proxy and Unicode

MySQL-proxy doesn’t seem to be able to connect to MySQL servers and use the utf-8 encoding. In order to ensure that the character set is always utf-8, you need to add the following lines to every MySQL server in your setup within the [mysqld] section.

skip-character-set-client-handshake
init-connect=’SET NAMES utf8’
default-character-set=utf8 

Comments (View)

permalink

UnicodeErrors in Django

There are times when in your Django application, displaying unicode strings can throw an except similar to:

UnicodeDecodeError at /contact/export

‘utf8’ codec can’t decode byte 0x92 in position 2: unexpected code byte

I’ve discovered that this might be due to a LOCALE setting that doesn’t support those unicode characters. To solve this problem, you have to change your LOCALE to something like UTF-8 that supports unicode characters.

From your shell, simply type:

update-locale LANG=en_US.UTF-8

Comments (View)

Mar
15th
Tue
permalink

The shortest way to install xdebug on Mac OS X

brew install xdebug

Then follow the instruction on how to enable it in php.ini

Comments (View)

Mar
8th
Tue
permalink

django flatpages and DEBUG = False

You’ll likely get a 500 error if you do this, you’ll need to create your 404.html and optionally 500.html templates to get this to work.

Comments (View)

Jan
29th
Sat
permalink

Comments (View)

Jan
28th
Fri
permalink

Django model versioning

I just learned about model versioning today. With model versioning, you can maintain history of all modifications made to your models (creation, deletion and updates) and have the ability to roll back (if necessary) those actions.

You can find a list of projects offering model versioning here: http://djangopackages.com/grids/g/versioning/

Comments (View)

permalink

Creating filtered Django fixtures

If you ever find yourself needing to create django fixtures from a select records in your database, here are steps that can help.

For the model you intend to export, you’ll need to modify your default object manager. I’ve include a snippet below showing an object manager with a modified get_query_set method:

 class LocationManager(models.Manager):
      def get_query_set(self):
          return super(LocationManager, self).get_query_set().filter(type__name=”Registration Center”)

Next, set your default object manager to this:

class Location(models.Model):

    objects = LocationManager()

Now you can do a ./manage.py dumpdata locations.Location and your generated fixture will be filtered based on your modified get_query_set.

Comments (View)

Jan
25th
Tue
permalink

Comments (View)