Snippet to update Django tables to utf8

So you get the dreaded illegal mix of collations:
Pythoneer » Convert MySQL table to utf8
Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE)
What do you do? Not too bad fortunately. And if you’re working with Django, it’s a little bit easier. Launch the shell with python manage.py shell. Then in the shell do something like [...]

A Django HttpRequest QueryDict is not your normal Python dict – i.e. getting ids from a friend request-form

Doesn’t work:
ids=request.GET['ids[]‘]
Does work:
ids=request.GET.getlist(‘ids[]‘)
A typical Facebook friend invite sends the ids to be invited to your site as an array in ‘ids[]‘. Normally, you can pull values out with just request.GET['key']. But since the value of this particular key is an array and not just a string, you can’t (at least I wasn’t able to) just [...]

Django snippets to check http_referer

Django snippets: Referer-checking view decorators

Here are a couple of Django decorators for limiting access to a view based on the request’s HTTP_REFERER. Both raise a Django PermissionDenied exception if the referer test fails (or a referer simply isn’t provided).

The first, referer_matches_hostname, takes a hostname
(and port, if specified) and matches it against the referer’s. [...]

Working with field level permissions with Django

This might be useful but, buyer beware.
Django snippets: FieldLevelPermissionsAdmin
Have you ever needed to customize permissions, for example, allow only some fields for editing by some group of users, display some fields as read-only, and some to hide completely? FieldLevelPermissionsAdmin class does this for newforms-admin branch. Not tested well yet (>100 LOC!).

1and1 and http compression

I have not been able to find any info about 1and1 and http compression. It’s a shame as it really reduces bandwidth, increases transfer speed, etc. Fortunately this little script does a really nice job of it. It’s in PHP and it works a treat on 1and1. With a bit of rewrite magic I should [...]

Neat little Facebook snippet for Django

You can use this to set up a Facebook User within you Django app. This of course uses the middleware which is optional as described here.
Django snippets: Little middleware that create a facebook user

Install **PyFacebook** package.

After make all steps in tutorial above, put this code in your [...]