Author Archive

-image-Extending Django’s user admin

The built in admin pages that you get in Django can be useful, but they particularly become useful once you start to add a lot more functionality to them.

For instance the Django’s User authentication system (which lives in django.contrib.auth ) is widely used, and quite often you need to extend the user’s profile by using AUTH_PROFILE_MODULE and a separate model. But having a separate Admin screen for this is kind of pointless.

In the admin.py file for your model which provides extra information (in my example it is called UserProfile just do the following:

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from models import UserProfile

class UserProfileInline(admin.TabularInline):
    model = UserProfile
    fk_name = 'user'
    max_num = 1
   
class CustomUserAdmin(UserAdmin):
    inlines = [UserProfileInline,]
    list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff', 'is_active')
   
admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)

Simple once you know how.


-image-gcc and python

Had an interesting little problem with gcc and python today on OS X 10.6.

Basically I was trying to use graphviz and pygraphviz, and installing from source I got messages like this:

gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -I/usr/local/include/graphviz -I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c pygraphviz/graphviz_wrap.c -o build/temp.macosx-10.3-i386-2.5/pygraphviz/graphviz_wrap.o
cc1: error: unrecognized command line option "-Wno-long-double"
cc1: error: unrecognized command line option "-Wno-long-double"
lipo: can't figure out the architecture type of: /var/tmp//ccD4Ow7T.out
error: command '
gcc' failed with exit status 1

This pointed to two problems I found:

  1. MacOSX10.4u.sdk being used
  2. “-Wno-long-double” being passed to gcc

Obviously I am on 10.6 and even though I do have that SDK installed it is the incorrect version. On some Xcode installations you won’t have it.

The remedy was to change the following file:

/Library/Frameworks/Python.framework/Versions/Current/lib/python2.5/config/Makefile

After backing up change all the instances of MacOSX10.4u.sdk to MacOSX10.6.sdk and then remove the flag -Wno-long-double

Then you should be able to compile from a normal python setup. For good measure I test easy_install as well and that worked smoothly..


-image-How do we kick our synchronous addiction?

How do we kick our synchronous addiction?

Really interesting post. Pity I don’t have the time to discuss it in more depth – too busying developing!


-image-Django settings in template

So what do you do if you require a django setting in your templates, much like we have MEDIA_URL today?

Well there are use cases for this, (if you are in doubt have a look at the original ticket for adding MEDIA_URL to django ).

The easiest way that I have found so far is to write a context processor. For example in my settings I might have JAVASCRIPT_URL (which in my real life code changes depending on whether I am running in debug, test or from a CDN):

JAVASCRIPT_URL = 'http://myjshost.com'

Now from here I would like to make this available in my templates. Create a new python file that is somewhere on your python path (Under my project, I create a utils directory and then put a file context_processors.py in there. Don’t forget __init__.py should live in that directory as well).

In the context_processors.py file simply put

def javascript_url(request):
    from django.conf import settings
    return {'JAVASCRIPT_URL': settings.JAVASCRIPT_URL}

In your settings.py file you might already have a reference to TEMPLATE_CONTEXT_PROCESSORS if not then add it like so:

from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
TEMPLATE_CONTEXT_PROCESSORS += (
     'django.core.context_processors.request',
     'django.core.context_processors.i18n',
     'appname.utils.context_processors.javascript_url',
)

And thats about it. From there on in you will be able to use JAVASCRIPT_URL like MEDIA_URL:

{{ JAVASCRIPT_URL }}

-image-The White Balance Lens Cap

Oh this is clever:

The White Balance Lens Cap: “

You may think automatic white balance is good enough. But if you’ve ever had to fix dozens (or even 100s) of photos with just slightly different colors, one-by-one, you know the true meaning of pain. The White Balance Lens Cap leaves you no excuse for not properly white-balancing every situation you encounter. Simply flip your camera into custom White Balance mode, snap a photo with your White Balance Lens Cap on, and your camera creates a perfect profile of the actual lighting in front of you. Best of all, unlike a gray card, the White Balance Cap takes no extra room in your gear bag. Just replace your existing lens cap with this one and you’ll always be able to white balance with no additional equipment.

(Via swissmiss.)


-image-Sugru

Awesome silicon based material for hacking anything – http://sugru.com/


-image-is that an iPhone or a MiniMac?

is that an iPhone or a MiniMac?: “



Love it.

(Via swissmiss.)


-image-Updating contact details

I have just spent the past 90 minutes updating contact details – much longer than it should take. Would be nice if I could just update say on Plaxo, and linkedin, Facebook etc would receive the updates but I guess we haven’t got to that stage yet. Have also sent out emails to lots of people, so apologies if you haven’t received one.

The main change is my mobile number – it belonged to vizrt, with whom my last day was officially the 31st of December. So please remove that from your records, I am waiting for company registration details to go through before I get a proper new mobile number but in the meantime reach me at tim@ the usual places or skype me on timchild.

Just to reiterate – my mobile number is no more.


-image-Christmas!

It’s been another Christmas, and almost a full year.

Christmas was good this year – Mum and Dad came over and spent it in Sweden, a little bit of time in Stockholm but mostly in the country. I think they really enjoyed meeting Harriet for the first time. Harriet enjoyed meeting them too but I don’t think that she really noticed Christmas this year.

She got lots of nice things to make her life cosy, her teddy bear and soft toy collection is growing almost as fast as her clothing collection is.

I seemed to spend most of the time cooking, this year was Beef and Moose Wellington. I would say it suits Beef better but it was good to try anyways.

So now its just some time before new year.


-image-LEGO CD Boombox

LEGO CD Boombox: “

LEGO

This looks awesome.

(Via swissmiss.)