Monday, December 22, 2008

Defining the Data Model for Django-Pledgedrive

Recently, I wanted to port a database application I had written using ASP into Rails. I had only made it so far using Ruby, but I still had the SQLite database sitting around. So, I started working on defining the models in Django and it prompted some questions:

What was the best way to start defining your model? Do you write it in django first and then rely on syncdb to build the database? What if you have an existing model? After some looking around, I found the command inspectdb. Which allowed me to automatically create the file based on structure I had already defined in the SQLite database with the commands:

export DJANGO_SETTINGS_MODULE=mysite.settings

cd mysite

python inspectdb >

However this introduced some issues all its own. In particular, fellow developer Milan Andric pointed out that I needed to:

  • remove all instances of id = models.IntegerField(primary_key=True)

    django automatically gives every model a primary key.
  • I also needed to remove:

    class Meta:
    db_table = u'...'

To view the difference in the code once it was cleaned up, see this diff

Additionally, Milan noted that I likely benefit from using __unicode__() to name my objects.

This morning, in looking over some previous conversations, I remembered that Milan had also suggested I look into the django-command-extensions module which provides some nice command line tools that (among other things) allows you to easily generate image files of you schema from django models. You can see an image of the current data model here:

Which I created this using the command:

python graph_models yourproject | dot -Tpng -o yourfilename.png

You can download the django-command-extensions here:

You can also watch a video of the the django-command-extensions tools in action here .

Tuesday, September 16, 2008

NPR Timeline Presentation (Beta)

Invariably, someone is going to ask me to stand up and present about the NPR API, the NPR Timeline, and the Portable Query Generator.  So, I thought I would get a jump on them by putting something together ahead of time:
Feel free to check it out and write your comments here or on the opensourcebroadcasting group.

Thursday, August 28, 2008

NPR API: Open-Sourcing Syndication?

I was asked by the folks at the Center for Social Media to Write an Article:

A Peek Under the Hood of the NPR API

"In our new article, KJZZ webmaster John Tynan offers a first-hand account of his efforts to develop a widget that allows users to create tailored timelines of NPR pieces. In the process, he describes not only new tools for media makers, but a rising ethos of collaboration in public broadcasting. “A cultural shift in the public broadcasting world is leading to a deeper understanding that truly public media is now technically feasible,” notes Tynan, who suggests a several next steps that pubcasting organizations could take to nurture future experiments."

Sunday, August 24, 2008

NPR / Timeline Mashup (Beta)

This is the companion blog for updates on a few select open source projects, such as the NPR Timeline Mashup. This mashup is an example of what can be done using the new NPR API.

This script owes an incredible amount to the NPR Digital Media team. You can find out more about the NPR API here. You can also read about what they're up to on their blog Inside

This also owes a great deal to the Simile Timeline project. You can read the documentation here, or ask a question about the timeline widget here.

If you would like to keep up with revisions to these pages, please feel free to checkout the latest files here or view additional details of the project here.