Archive for February, 2010

  1. 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.

    By timc3 on the
    February 18th, 2010
  2. 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..

    By timc3 on the
    February 18th, 2010