Brad's Blog

web dev, django, running, food, or whatever

Chosen.js in the Django admin 2011-12-13

Update Nov 23, 2013: I've written a little app (django-chosenadmin) that'll automatically add this to every app. Quite some time ago, I ran across the chosen.js plugin for jQuery and Prototype (I'm using the jQuery flavor). My first thought upon seeing this was, "This would rock in Django's admin app." Yet for some reason, I didn't make that happen.Until recently. I maintain a project where about 10 people use the admin app extensively. They manage several apps that have foreign ...

Think Different. 2011-10-06

There's a lot of buzz on the net about Steve Job's death, and rightly so. For those of us that work in or around the tech world, he was a giant. I fully attribute his company's products (the iPhone and the iPad) to what I like to think of as a renaissance in computing. These devices have changed the way we think about computers, the web, and what software can be—mobile & fully integrated into our daily lives. And not ...

SiteSprint III - An update 2011-01-24

This post, a followup to my previous post, is now about 2 months overdue. I have to admit, I'm glad I participated in SiteSprint, but I'm fairly disappointed in the amount of work that I accomplished. So, without further ado, here's the update on what happened.Success!Set up a Django stack running nginx, gunicorn, postgresqlSet up MezzanineMigrated my blog posts and comments from BloggerFor a weekend of work, this really wasn't too bad. I like Mezzanine for publishing, and I like ...

Fix: Leopard libedit detected. 2011-01-05

If you use iPython on OS X, you've probably seen this: Leopard libedit detected., and then noticed some very quirky behavior related to spacing, and command history. In short, that behavior is related to default version of the readline library bundled in OS X (It's not GNU readline). If you use pip and virtualenv, just instalilng readline doesn't help. So, how do you fix this? Well, the quick and dirty way to fix this is with:easy_install -a readline For the whole ...

SiteSprint III - The Reclaimation 2010-11-02

My personal website is a disgrace. As a web developer, I find it embarrassing that my own site is a cobbled-together mess of PHP and static html. Only slightly less embarrassing is my blog, which is obviously hosted on Blogger. Even though Blogger has recently added a few new themes, I'm still unhappy with the look-and-feel of my blog. So, since SiteSprint III has officially started, I'm taking this opportunity to Reclaimâ„¢ my personal website.Tech Specs - the easy partI've ...

Python: stray commas cause tuples? 2010-10-15

As I try to debug a strange problem in a Django view, I notice a stray comma after a dictionary definition. So I jump over to a python shell, and guess what? Ending a literal dict with a comma creates a tuple. >>> d = {1:'foo'},>>> type(d)<type 'tuple'>>>> d({1: 'foo'},)>>>

A case for values_list 2010-07-19

Here's the Scenario: I have a model (lets call it Contact) with two Foreign Keys, one of which is related to User in Django's contrib.auth app. I need to build a form that lets me select an existing object, and a new user. class ContactType(Model): name = CharField(max_length=128)class Contact(Model): user = ForeignKey(User) contact_type = ForeignKey(ContactType) # possibly more fields...I need to select from existing models, so my first thought might be to build a form that uses two ModelChoiceField's. I ...

PyGraphviz on OS X (SL) with virtualenv 2010-07-14

There's this cool project called django-extensions that (among other things) adds a lot of commands to django's manage.py offerings. One of which is ./manage.py graph_models [appname] which will generate a nice graph displaying the relationships among all of your Models. This comand needs pyGraphViz, though, and I was a little disappointed when i discovered I couldn't install pyGraphViz with pip install pygraphviz. (ok, a lot disappointed). I eventually got this working, and here's how:First, install the development snapshot of GraphViz: ...

Vim Syntax highlighting for Apache Config Files 2010-06-09

I use Django with Apache and mod_wsgi. Each project that I work on has different apache config files, so I like to keep those in the same mercurial repo that contains my django project's code.For some time now, it's been bugging me that vim doesn't do syntax highlighting for those apache configs (nor the wsgi files). I finally decided to do something about it, and I'm glad I did, because it's a fairly simple fix:My project directory layout often look ...

Convert Tables to Unordered Lists 2010-05-28

If you've ever had the pleasure of working with old HTML content, you've surely seen some <table>'s where they don't belong. Lately, that's the sort of thing I've been dealing with on a regular basis, and for some reason, I often see a list of information in a table.Wouldn't it be nice if there were an easy way to turn these tables into unordered lists? Thanks to BeautifulSoup, this is really not that difficult.Here's the code:from BeautifulSoup import BeautifulSoup, Tag ...