Brad's Blog

Published: 2013-02-08

The Minimum Working Thing

entrepreneurship programming startups web

This was originally a guest post that appeared on Nibletz. The original link is here: I've been pondering this post for a long time. Any student of startups is probably familiar with the phrase Minimum Viable Product. It's really a simple idea, and I think it embodies an important philosophy for anyone starting a company. The idea is that your product (whatever it is; e.g. a service, a physical thing ...

Published: 2012-10-30

Customizing Django's password_change view

django programming python web

If you have a site where users have the traditional username/password combination, you've got to provide some way to let users change their password. Luckily, this is fairly easy to do with Django. The auth app comes with a password_change view that does what you'd probably expect. It's also fairly easy to set up. You add a line similar to the following to your root URLConf: url(r'^accounts/', include('django.contrib.auth.urls')), You also ...

Published: 2012-06-11

Building a Happy Potty

ios javascript mobile web

This past weekend, I particpated in Memphis's 48 Hour Launch. It's a weekend-long event where anyone can pitch a business or app idea on a Friday night, try to get enough people to buy into the idea, and form your team. Then, you spend the weekend building something, and on Sunday you get a chance to showcase what you've accomplished. I was fortunate enough to team up with a few friends (and some new ones!) to build ...

Published: 2011-12-13

Chosen.js in the Django admin

chosenjs django javascript jquery python web

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

Published: 2010-11-02

SiteSprint III - The Reclaimation

django sitesprint web

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

Published: 2010-07-19

A case for values_list

django python web

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

Published: 2010-05-28

Convert Tables to Unordered Lists

BeautifulSoup Programming Python web

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

Published: 2010-04-22

Pretty options for Django's auth.User

Python django web

Several of my Django Apps have Foreign Key relationships to django.contrib.auth.model.User. In Django's admin app, these show up a select elements displaying the username attribute. For some people, that may be OK, but for most of the people with which I work, it's not. We want to see prettier options, i.e. each User's full name as the options in that select element.So, here's how it works. We override the ModelChoiceField ...

Published: 2010-03-23

On select_related()

Python awesome django web

If you use Django, and your models have relationships that span across multiple tables, you need to read this: is awesome.That is all.

Published: 2009-11-24

Sticky Groups

Linux web

I often deploy web projects in a directory that's not owned by the user under which my webserver runs. Therefor, I often have to change permissions so the webserver can read from or write to certain files. So, for this example, let's assume I'm logged in to my linux box as brad, and I'm using apache which runs under the user www-data. To give apache access to my public_html directory, I'd change ownership for the ...

Published: 2009-07-14

A for AJAX - OR - Dynamically generating options for a select element.

Javascript Prototype ajax web

I don't do a lot of AJAXy web development, but when I do, I usually make use of Prototype. I've recently created a form containing a <select> element whose <option>s are dynamically generated via an AJAX request. The problem however, is that a selected option was already in the form. So before the AJAX request, my HTML looked something like this:<select name="s" id="s"><option value="val1">Value 1</option><option value="val2" selected="selected">Value 2</option><option value="val3">Value ...

Published: 2009-06-30


Python django web

I'd just finished the first version of a new django app (myapp), and so I pushed it out to my development server. All the new code was in place, so I ran python syncdb. The result?Traceback (most recent call last): File "", line 11, in <module> execute_manager(settings) File "/usr/local/lib/python2.6/site-packages/django/core/management/", line 340, in execute_manager File "/usr/local/lib/python2.6/site-packages/django/core/management/__init__ ...

Published: 2009-06-26

"Adding" Q objects in Django

Python django web

I've got a Django app with the following Model:class Story(models.Model): title = models.CharField(max_length=255) content = models.TextField()The Problem: I wanted to build a simple search feature that OR'ed all the search terms. Essentially, I wanted SQL resembling the following:SELECT * from myapp_stories where title LIKE '%term1%' OR content LIKE '%term1%' OR title LIKE '%term2%' OR content LIKE '%term2%'; The Solution: You can add django's ...

Published: 2009-05-06

Data Truncated Errors

Python django mysql web

I recently ran into some of the Data truncated for column ... errors in my django apps. After a little digging, I've discovered that my particular problem lie in the structure of the underlying MySQL tables. Particularly with varchar columns. I have a model that contains a FileField:class MyModel(models.Model): file = models.FileField(upload_to="files/%Y/%m/%d")Note that the MySQL table generated by this model will look something like the following:+-------------+--------------+------+-----+---------------------+----------------+| Field | Type | Null | Key | Default ...

Published: 2009-05-01

Have Apache Force File Downloads

apache django web

I have a Django app that lets users upload files. Any kind of file. It's nice that Apache will let me force file downloads based on the files extension. <LocationMatch "\.(gz|tar|pdf|docx|doc|xls|xlsx|bz2|zip)$"> SetHandler None Header set Content-Disposition attachment</LocationMatch>So, in my HTML/templates: all I have to do is this:<a href="SomFile.docx">Some File</a>

Published: 2009-04-24

Restricting Access by Group in Django

Python django web

Django's authentication system provides built-in support for Groups. When developing an app, you may want to prevent users in a particular group from accessing part of your app. For example, if you were building a tool to be used by Faculty and Students, it's quite possible that there would be parts of the app you wouldn't want Students to access (like the part that allows a User to change grades!). Luckily, there's a decorator called user_passes_test ...

Published: 2009-04-21

Dynamically Displaying Fields in a ModelForm

Programming django web

The Problem: I want to dynamically include some fields in a ModelForm based on some external criteria. Sometimes I want the fields displayed, sometimes I don't. I'm going to try to explain this scenario through a (albeit contrived) example. I have a Model that looks like the following:class Suff(models.Model): foo = models.CharField(max_length=255) bar = models.BooleanField(default=False, blank=True) def is_foo_bar(self): ''' is this model's foo attribute set to 'bar' ''' return ...

Published: 2009-04-01

How to Set up a Foreign Key Constraint in MySQL

Programming mysql web

The default storage engine in MySQL (MyISAM) does not support Foreign Key constraints. If you want to use Foreign Keys in Mysql, you need to use InnoDB.The following is a simple example that illustrates Foreign Key constraints, we'll create tables to store information about Authors and their Books. The Foreign key will link a book to an Author. Note, that in MySQL we need to use the InnoDB storage engine to support Foreign Key Constraints.First, we need ...

Published: 2009-02-20

Scheduled Tasks (or cron jobs) with Django

Python cron django web

This is my take on setting up cron jobs for the apps in a Django project. It is based on my own convention, and it solves my initial problems where I want to perform some action on all of my Django apps at a periodic interval (currently this is a once-a-day task).In order for this to work, I create a module for all of my INSTALLED_APPS. This module must contain a run method. Other than that, it ...

Published: 2009-01-14

A Custom form for Django's Automatic Admin.

Python django web

A huge selling-point for Django (at least for developers) is its Automatic Admin. However, the ease at which the Admin can be set up, might make one second-guess an attempt to customize what is provided by default. Of course, the default admin site may not be without its drawbacks...Many of the django Apps that I have built, tap into Django's User Authentication System. Simply put, when I build a model, it has a Foreign Key to django's ...

Published: 2008-12-17

How to convert HTML to PDF using Python.

PDF Python web

I'm building web-based, data-driven apps using Django. Eventually (or unfortunately), I will need to generate some reports that are printer-friendly. Logically, PDF is the format for such files... so how am I going to convert my xHTML and CSS to a nice-looking PDF document?The Django Book has a whole chapter dedicated to Generating Non-HTML Content. They seem to to be fond of ReportLab ToolKit. The caveat here, though, is that you need to know a bit about the ...

Published: 2008-11-17

Soup's On! And it IS Beautiful!

Programming Python web

Here's the problem: There's a BAJILLIION static html pages sitting out on a server, and I need to migrate all that content to a new Database-driven CMS. Additionally, I need to get rid of a lot of non-essential hard-coded presentational markup (like align="center" or font="whatever") and any inline styles that may exist... (you know, because external CSS is the way to go).I could spend hours and hours just copy-/pasting stuff... but meh. Enter BeautifulSoup ...

Published: 2008-09-04

Safari is Cooler than you Think!

Apps OS Safari X web

When you really start digging into Mac OS X, it's fairly mind-boggling how much extra stuff it has that your average user never sees. I recently encountered a problem on my MacBook Pro, where the Optical Audio was overriding my internal speakers, which prevented me from hearing any audio (without using headphones). Unfortunately, there's no easy-to-access preference pane to enable or disable various audio devices. This led me on a search for command-line utilities to manage system preferences ...

Published: 2008-08-13

Net Neutrality

networking web

Save the Internet | Rock the Vote

Published: 2008-08-12

How to update an input value with the value from a selected option using Prototype

Javascript Programming web

Today, I needed to set the value of an HTML input element based on the value of a option in a select element. This is fairly easy to do with Prototype's writeAttribute. Here's an example:A simple javascript function to do the work:function populate_input(){ var field = $('tf_select').getValue(); $('tf').writeAttribute('value', field);}A simple HTML snippet to see it in action:<div><p><select id="tf_select" name="tf_select" onchange="populate_input();"><option value="">- choose one -</option><option value="v1">value ...

Published: 2008-07-15

The Structure of a Django App

Programming Python django web

Previously, I'd lamented the difficultly present in choosing an web development framework. I'd worked through several symfony tutorials, and though I could see the benefits down the road, it just didn't feel right to me (yes... "feel" is a technical drawback).So, I checked out a copy of Django, and I haven't looked back. If you're the least bit proficient with python, and you need to build a database-driven web site, USE DJANGO! They have ...

Published: 2008-06-17

Lions, Tigers, and Web Development Frameworks, oh my!

Javascript Programming Python php web

Apparently I've stumbled upon a problem that has recently faced many web developers. That is, I would like to adopt an open-source web development framework for mid-sized project. Well... searching that phrase only yields 200,000+ results. So how does one choose?I guess Ruby on Rails sparked the whole "Web Development Framework" movement (among other things). I've typically used PHP for my web-based projects in the past, but over the last 2 years, I've also become ...

Published: 2007-07-13

Building Apps for the iPhone

iPhone web

So there was this little get-together called iPhoneDevCamp last weekend (July 6-8, 2007), and since I'm just over 2000 miles from San Francisco, I missed out. However, in just under a week, there seems to have been a flood of great iPhone applications. To find out what I mean, just check out a google search, OR, head right on over to the iPhone Application List.So, in such a short time since the iPhone's release, how have so ...

Published: 2007-02-27

Javascript: What is the standard?

Javascript Programming web

I've recently been writing a little javascript, and I needed to chage the value of some text inside an html/xhtml element. It seems there are several ways to do this, but evey browser may or may not support the same method for doing it (big surprise, here) I'm not sure what is considered the "standard" way. Here's a little script that I use to help me decide which browsers support which methods for altering text within ...

Published: 2006-07-24


Fun Programming web

Occasionally, I run across some project that's implementing an idea that I've had ... That's the case with YouOS. I think I even wrote a paper about it in 1998, but that's what happens when your lazy (read: too many other things you have to do!)I created an account, and though it was a little slow for my wife's laptop, YouOS is really a very impressive project. Now, all the world needs is a very ...

Published: 2006-05-10


Programming web

Wow... the Net never ceases to amaze me. I've been a fan of for a while, but I never realized they were using OpenLaszlo! So, after a skimming over the OpenLaszlo site, I ran across a link to which bascially allows you to draw diagrams in your browser. Sweet!