Friday, January 23, 2009

Installing mod_python on Mac OS X Leopard (10.5.x)

Apache2 comes pre installed on Mac OS X Leopard as does Python (2.5). But it doesn't come with mod_python. Here is what you need to do to get it to work.

download the latest file from I downloaded (mod_python-3.3.1.tgz)
$ tar xvzf mod_python-3.3.1.tgz
$ cd mod_python-3.3.1
$ ./configure --with-apxs=/usr/sbin/apxs

Now we need to patch the make file so that it will work correctly. edit src/MakeFile

  • Add -arch x86_64 -arch ppc -arch i386 to the end of the LDFLAGS line.

  • Add -arch x86_64 -arch ppc -arch i386 to the end of the CFLAGS line.

  • Under the target add the following to the line after the -c -Wc,"-arch x86_64" -Wc,"-arch ppc" -Wc,"-arch i386" so my complete line looks like. $(APXS) $(INCLUDES) -c -Wc,"-arch x86_64" -Wc,"-arch ppc" -Wc,"-arch i386" $(SRCS) $(LDFLAGS) $(LIBS)

When that is done:
$ make
$ sudo make install

and then:

$ cd /etc/apache2
$ sudo cp httpd.conf httpd.conf.orig
$ sudo emacs /etc/apache2/httpd.conf

Add the following to the httpd.conf file.

LoadModule python_module libexec/apache2/

Restart apache
$ sudo /usr/sbin/apachectl restart

Test configuration
sudo /usr/sbin/apachectl -t

That is all, if there are no errors, it worked!

Labels: , ,

Wednesday, January 21, 2009

Django Query using value from another field in same table

I came across a query that seemed like it should be pretty easy, but it wasn't.

Suppose you have the following Model Class.
# pseudo code.
class Person(models.Model):
first_name = models.CharField()
last_name = models.CharField()
I would like the query to return all Person's who have the same first_name and last_name

My first guess was to do the following.

person_list = Person.objects.filter(first_name=last_name)

but that doesn't work because it wants to have last_name as a variable.

This is what I ended up doing.

person_list = Person.objects.extra(where=['first_name=last_name']

You could also do it using a models.Manager, if that is what you prefer.

Even though this is an edge case, I'm not sure why Django doesn't support this out of the box, but I am pretty sure there is a pretty good reason.

Labels: , , ,