Brad's Blog

web dev, django, running, food, or whatever

How to Set up a Foreign Key Constraint in MySQL 2009-04-01

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 to create a ...

Public Keys don't like write access! 2009-03-25

The first part of my Automatic Backups with cron, tar, and SSH details how to set up remote login (sans passwords) using RSA public key.Apparently this doesn't work if your home directory allows groups or others write access. So if used ssh-keygen -t rsa to generate a public key which you added to a remote host (under .ssh/authorized_keys), but ssh is still prompting you for a password, try setting your home directory's permissions to something like 0755 (or remove write ...

mod_python checks your blood pressure 2009-03-24

I'm deploying a django project using mod_python... now, usually I will just use my package management tools to install a binary version, but this time I need to build it from source.As I get ready to go through the whole configure/make/make install process, I peruse the output of configure just to make sure everything is ok...checking for gcc... gccchecking for C compiler default output file name... a.outchecking whether the C compiler works... yeschecking whether we are cross compiling... nochecking for ...

Scheduled Tasks (or cron jobs) with Django 2009-02-20

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 cron.py module for all of my INSTALLED_APPS. This module must contain a run method. Other than that, it can work ...

A Custom form for Django's Automatic Admin. 2009-01-14

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 User Class.Here's an ...

Add a Context Processor for your Django app using Sites 2009-01-05

I've recently refactored a significant number of my Django Apps so that they include the "sites" framework. Essentially, this allows me to use the same code (and database) for multiple sites. For Example, if I was was building a CMS (and I am!), I might have a model that defines a "page":from django.db import modelsfrom django.contrib.auth.models import Userfrom django.contrib.sites.models import Siteclass Page(models.Model): title = models.CharField('title', max_length=255) content = models.TextField() author = models.ForeignKey(User) sites = models.ManyToManyField(Site, help_text="This page will be displayed ...

Morphology is Fun! 2009-01-04

Morphological operations are very common in image processing. The two most basic of these are Erosion and Dilations, and from these, additional morphological operations can be performed. While there is an abundance of literature on the topic of morphology, I often like to view concrete examples of the operations. So, I've published a few images that illustrate the output of 1-to-5 iterations of various morphological operations --erosion, dilation, opening, closing, gradient, top hat, and black hat--with various structuring elements--rectangle, cross, ...

How to convert HTML to PDF using Python. 2008-12-17

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

radiohead - 15 steps video 2008-12-04

Updated... BIZRADv2... is a bit better.rh.createWidget("BIZRADV2", "4G5D1F9F2F0G8I9H1F5F2E0D5E1F7C8F5GaK3E1G5D1C2E4C8C9C7C6F4D5DaD9E8D5D1K9D8D7D1D0G5D2E1D4DaD9D6D3E5D1C2E5D3D4DbD0D4E1D5DaD9D8C7H2D4E9E7D5C1E3D1D2D5D7C8EaD9D1H3D1D7DaE6D5C1D3E7F4D8CaD9DaD1C2C1C0F2C1C2D0D7D8D6E9FaH3C4F1G3H5F4E0E1G8DaC9D3E2G1D5E8C7E6E4C3E0CaFbD7J");

That Looks about Right 2008-12-04

history | awk '{ print $2 }' | sort | uniq -c | sort -rn | head 152 cd 145 ll 73 vi 20 rm 18 svn 13 exit 9 ls 8 grep 7 php 5 wgetvia b-list.org