Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
You need an editor
I’m supposed to be this expert on writing, right? So how come my previous articles have had so many errors? Simple: my blog doesn’t have an editor. That’s typical for a blog, but it’s unfortunately also typical of open source documentation: the vast majority of technical documentation doesn’t reach far beyond rough draft status. All good writers have a dirty little secret: they’re not really that good at writing. Their editors just make it seem that way. -
Django Golf Handicap Tracker
Django Handicap Tracker Screenshot This is the first Django application I ever built. It was started in the 0.96 days and I have since ported it to 1.0. It mostly works and now supports multiple users using the django-registration and django.contrib.auth module. I haven't done much work on it though. Eventually I will put it online for all to use. SVN path: http://svn.davidgrant.ca/repos/src/python/django_handicap Relative path in repository: /src/python/django_handicap SVN revision log View in Trac -
Django Golf Handicap Tracker
[img_assist|nid=361|title=Django Handicap Tracker Screenshot|desc=|link=popup|align=right|width=100|height=77] This is the first Django application I ever built. It was started in the 0.96 days and I have since ported it to 1.0. It mostly works and now supports multiple users using the django-registration and django.contrib.auth module. I haven't done much work on it though. Eventually I will put it online for all to use. Website: Golf Handicap tracker at github.com -
django-evolution aka orm pain part 2
Finally bit the bullet and tried out a new application to help me do the changes I needed to do on the db and boy am I glad I did. django-evolution is a joy to use. It's easy to install with no strange dependencies and it did everything out of the box as described. Initially somethings did trip me up such as the django-evolution's initialization actually looks only at the models.py and does not actually bother what is really in the db, as in say the models.py you define a field that is not actually in the db during the first 'python manage.py syncdb' to create the django-evolution table, it does not actually know that and will just carry on not knowing that there are discrepancies between the models.py and the actual db. After I figured that part out, it was easy. Just add the fields and their attributes, re-run an update script on my data and everything is done. Now my selects are much faster. Initially a 3k row db select was taking 50s and now using the caching functionality of select_related() it comes back in a blazing 4s. Ah here too initially I got tripped a bit as … -
Technical style
Now that I’ve discussed what kinds of technical documentation to write, I can move on to the question of how to actually develop a writing style that produces great technical documentation. Learn to write Unfortunately, there aren’t any shortcuts here. The best way to learn how to write great documentation is to first learn how to write (anything). There are some important differences between technical documentation and your average prose, but a solid foundation of good written communication skills is an irreplaceable prerequisite. -
When Django Fails? (A response)
I saw an article on reddit (or was in hacker news?) that asked the question: what happens when newbies make typos following the Rails tutorial, and how good of a job does Rails do at giving useful error messages? I decided it would be interesting to apply this same question to Django, and see what the results are. I didn't have the time to review the entire Django tutorial, so instead I'm going to make the same mistakes the author of that article did and see what the results are, I've only done the first few where the analogs in Django were clear.Mistake #1: Point a URL at a non-existent view:I pointed a URL at the view "django_fails.views.homme" when it should have been "home". Let's see what the error is: ViewDoesNotExist at / Tried homme in module django_fails.views. Error was: 'module' object has no attribute 'homme'So the exception name is definitely a good start, combined with the error text I think it's pretty clear that the view doesn't exist.Mistake #2: misspell url in the mapping fileInstead of doing url("^$" ...) I did urll: NameError at / name 'urll' is not definedThe error is a normal Python exception, which for a … -
Vancouver Sun Parking Tickets Website Screen Scraper
When the Vancouver Sun came out with their Vancouver parking tickets database I immediately had some burning questions, like, did the meter maids work on holidays? Do the work less in the evening than during the day? I found it difficult to answer these questions using their interface, so I decided to screen scrape all 1.6 million parking tickets in to my own MySQL database. This was a bit challenging as they made it difficult to screen scrape the data but eventually it could be done simply by first getting an AppKey, a hidden value inside the HTML source and then doing queries using that AppKey as a parameter. It took about a week to get all 1.6 million tickets downloaded. By using Django, it was easy to get them in to a database and view the results. Initially I just put all the data in to one table, then later I decided to normalize the data a bit which was interesting as I decided to do that in pure SQL which I hadn't done before. I did the scraping itself using a combination of BeautifulSoup, lxml, and mechanize. vancouver-parking-tickets project at GitHub MySQL SQL dump (42 MB) Here's some … -
Vancouver Sun Parking Tickets Website Screen Scraper
[img_assist|nid=367|title=|desc=|link=none|align=right|width=150|height=146] When the Vancouver Sun came out with their Vancouver parking tickets database I immediately had some burning questions, like, did the meter maids work on holidays? Do the work less in the evening than during the day? I found it difficult to answer these questions using their interface, so I decided to screen scrape all 1.6 million parking tickets in to my own MySQL database. This was a bit challenging as they made it difficult to screen scrape the data but eventually it could be done simply by first getting an AppKey, a hidden value inside the HTML source and then doing queries using that AppKey as a parameter. It took about a week to get all 1.6 million tickets downloaded. By using Django, it was easy to get them in to a database and view the results. Initially I just put all the data in to one table, then later I decided to normalize the data a bit which was interesting as I decided to do that in pure SQL which I hadn't done before. I did the scraping itself using a combination of BeautifulSoup, lxml, and mechanize. vancouver-parking-tickets project at GitHub MySQL SQL dump (42 MB) Here's … -
Django Recipes Application
Django Recipes Screenshot django-recipes at Google Code My mom was writing a family cookbook using Microsoft Word and I thought this was a bad idea for several reasons. At first I thought about using LaTeX to separate the style from the content a bit, then I thought about using XML, then I settled on a database as being the most generic to store recipe data. I quickly decided on using Django to create this cookbook framework because Python is probably my strongest language and it makes creating custom websites really easy. So far it includes: Most important models, Recipe, Ingredient, Direction, Category, Food. Very nice admin interface for creating recipes with inline ingredients and directions. Front-end: only a recipe_list and recipe_detail so far, but the recipe_detail has an experimental method of displaying recipes that is based on this LaTeX style: http://www.ctan.org/tex-archive/macros/latex/contrib/cooking/ (apparently based on style in a famous German cookbook by Dr. Oetker (Gromzik, J.; Reich, C.; Sander, C. (ed.): Dr. Oetker Schulkochbuch – Das Original. Ceres, Bielefeld, 1996.) Competitors/related projects: KRecipes - KDE-based desktop recipes software. Ben Collins-Sussman's effrecipes - Simple, but it works. Not under active development. Recipes on Rails - Ruby on Rails recipes site. Not open … -
Django Recipes Application
[img_assist|nid=362|title=Django Recipes Screenshot|desc=|link=popup|align=right|width=98|height=100] My mom was writing a family cookbook using Microsoft Word and I thought this was a bad idea for several reasons. At first I thought about using LaTeX to separate the style from the content a bit, then I thought about using XML, then I settled on a database as being the most generic to store recipe data. I quickly decided on using Django to create this cookbook framework because Python is probably my strongest language and it makes creating custom websites really easy. So far it includes: Most important models, Recipe, Ingredient, Direction, Category, Food. Very nice admin interface for creating recipes with inline ingredients and directions. Front-end: only a recipe_list and recipe_detail so far, but the recipe_detail has an experimental method of displaying recipes that is based on this LaTeX style: http://www.ctan.org/tex-archive/macros/latex/contrib/cooking/ (apparently based on style in a famous German cookbook by Dr. Oetker (Gromzik, J.; Reich, C.; Sander, C. (ed.): Dr. Oetker Schulkochbuch – Das Original. Ceres, Bielefeld, 1996.) Competitors/related projects: KRecipes - KDE-based desktop recipes software. Ben Collins-Sussman's effrecipes - Simple, but it works. Not under active development. Recipes on Rails - Ruby on Rails recipes site. Not open source as far as … -
Multiple Sites, Single Login with Django
One of the biggest barriers to entry on the web might be the "register -> check email -> login -> remember account info" paradigm. At work I recently developed a proof-of-concept app that allows a single login to work with multiple sites. How? iframe -
The State of MultiDB (in Django)
As you, the reader, may know this summer I worked for the Django Software Foundation via the Google Summer of Code program. My task was to implement multiple database support for Django. Assisting me in this task were my mentors Russell Keith-Magee and Nicolas Lara (you may recognize them as the people responsible for aggregates in Django). By the standards of the Google Summer of Code project my work was considered a success, however, it's not yet merged into Django's trunk, so I'm going to outline what happened, and what needs to happen before this work is considered complete.Most of the major things happened, settings were changed from a series of DATABASE_* to a DATABASES setting that's keyed by DB aliases and who's values are dictionaries containing the usual DATABASE* options, QuerySets grew a using() method which takes a DB alias and says what DB the QuerySet should be evaluated against, save() and delete() grew similar using keyword arguments, a using option was added to the inner Meta class for models, transaction support was expanded to include support for multiple databases, as did the testing framework. In terms of internals almost every internal DB related function grew explicit passing of … -
What to write
Tech docs can take a bunch of different forms ranging from high-level overviews, to step-by-step walkthroughs, to auto-generated API documentation. Unfortunately, no single format works for all users; there’s huge differences in the way that people learn, so a well-documented project needs to provide many different forms of documentation. At a high level, you can break down the different types of documentation you need to provide into three different formats: -
How to Log Something
With The Django Debug Toolbar Somewhere in your Python code (not a template): import logging logging.debug(something_you_want_to_log) With Firebug Somewhere in your JavaScript or the Firebug Console: console.log(something_you_want_to_log); That was easy. Sources Alex Firebug Console API -
My travel kit
I travel quite a bit. This means I’ve often experienced a particularly geeky form of pain: the frustration of missing that one cable or power adaptor I really need. This has happened to me enough times that over the years I’ve grown into something of tech readiness geek. My travel kit now has all sorts of adaptors and cables; I thought it’d be amusing to dump out my travel bag and actually enumerate all this crap. -
When you play outside of django's ORM ... you get pain!
For one of my projects, I forgot to implement the relationship of one my models. I thought I could get away with it by writing a tag that made a query to the db upon being fed a string in the report. To my horror, this caused the report to take about 50seconds to generate for a paltry 3000 record db! Upon tailing the logs of query.log, I found that the multitude of query to the db was causing the problem. It was basically hitting the db about 3000+ times for a single page report. That is when I found out the good thing about Django's select_related(). The problem now is, I do not have that relationship and need to build that relationship into the db. Not exactly fun with a db that is already populated with data. Led me to thinking, while Django's ORM might be great for stuff like calling data from another table, but would it also incur a performance hit everytime data is being queried. I have heard Django being used for high traffic sites but then are these high traffic sites?I tried looking around but I could not find a satisfactory answer to this: "What … -
Önskan till Binero om Django
hej -
Önskan till Binero om Django
hej -
Setting up inline forms in contrib.admin
This recipe covers how to set up inline forms in contrib admin and how to show foreign keys in those inline forms. -
Branching and merging in real life
At work I still mostly use Subversion for version control. Its main selling points: stable, performs as expected, integrates nicely with Trac, holds all our old stuff (legacy inertia). Note that "pain-free branching and merging" is not on that list. (And don't give me the old "branching is cheap in svn!" line. It's not about the branching, it's about the merging.) A couple years ago I started also using Mercurial and plan to eventually replace svn with it entirely. The aspect of Mercurial that made my life better recently is its support for branching and merging. The scenario: an important internal web app (in use all day every school day) needed some significant changes on a short timetable. Normally I'd work on the app thus: edit the staging copy, commit, update the live copy. I didn't want to take that approach here. I knew that during the development window there might arise unrelated urgent change requests; I wanted to keep the new code isolated during development, but also deploy and track those unrelated urgent changes. Branching seemed like the right approach. I could have made a full clone of the app (hg clone mainrepo newrepo). However, handling environment dependencies (web … -
Towards a Better Template Tag Definition Syntax
Eric Holscher has blogged a few times this month about various template tag definition syntax ideas. In particular he's looked at a system based on Surlex (which is essentially an alternate syntax for certain parts of regular expressions), and a system based on keywords. I highly recommend giving his posts a read as they explain the ideas he's looked at in far better detail than I could. However, I wasn't particularly satisfied with either of these solution, I love Django's use of regular expressions for URL resolving, however, for whatever reason I don't really like the look of using regular expressions (or an alternate syntax like Surlex) for template tag parsing. Instead I've been thinking about an object based parsing syntax, similar to PyParsing.This is an idea I've been thinking about for several months now, but Eric's posts finally gave me the kick in the pants I needed to do the work. Therefore, I'm pleased to announce that I've released django-kickass-templatetags. Yes, I'm looking for a better name, it's already been pointed out to me that a name like that won't fly in the US government, or most corporate environments. This library is essentially me putting to code everything I've … -
The Django community in 2009
In March of 2007, I attempted to measure the size of Django’s community. That March turned out to be a major inflection point in Django’s growth: the release of 0.96 brought a lot of new features – testing and the new forms library being the critical ones – and those in turn brought in a lot of new users. Growth since then has been at a much faster pace. So I thought it’d be interesting to review the same metrics I used back then. -
Thank you, Rails
It’s fashionable, or perhaps inevitable, for tech communities to trash their competition. The Emacs folks like to mock vi users; Windows folk look down on us Mac users (and Linux users mock us both); and everyone likes to mock PHP despite PHP’s dominance in the web world. We geeks make arguing over minor technical points into a kind of art. This is all pretty understandable: it’s easy to define community in terms of what we’re not. -
Setting up a python CI server with Hudson
Installing Hudson I start with a basic virtual machine – in this case, I’m using Ubuntu Server 9.10. Once you have a basic machine installed, I recommend you make sure everything’s up to date with patches. sudo apt-get update sudo … Continue reading → -
On commit bits
Commit bits What’d you do the day you started your job? Got a little tour. Found your desk. Some HR paperwork. Figured out the network. Set up your new company machine. Got your VPN credentials. And got your commit access to the company’s source control. Normal first day procedure, I know. And yet, that day-one-commit-bit is one of the starkest differences between the corporate and the open source development model.