Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
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. -
Django's ManyToMany Refactoring
If you follow Django's development, or caught next week's DjangoDose Tracking Trunk episode (what? that's not how time flows you say? too bad) you've seen the recent ManyToManyField refactoring that Russell Keith-Magee committed. This refactoring was one of the results of my work as a Google Summer of Code student this summer. The aim of that work was to bring multiple database support to Django's ORM, however, along the way I ran into refactor the way ManyToManyField's were handled, the exact changes I made are the subject of tonight's post.If you've looked at django.db.models.fields.related you may have come away asking how code that messy could possibly underlie Django's amazing API for handling related objects, indeed the mess so is so bad that there's a comment which says: # HACKwhich applies to an entire class. However, one of the real travesties of this module was that it contained a large swath of raw SQL in the manager for ManyToMany relations, for example the clear() method's implementation looks like: cursor = connection.cursor() cursor.execute("DELETE FROM %s WHERE %s = %%s" % \ (self.join_table, source_col_name), [self._pk_val]) transaction.commit_unless_managed()As you can see this hits the trifecta, raw SQL, manual transaction handling, and the use of a … -
Merges from the Crypt - or, how I learned to stop worrying and love SQL
Outlining how I merged two databases for django-powered sites using a combination of SQL, django-multidb, and pg_dump. -
How to set up cherokee and uWSGI
A couple of post ago I have "blogged" about cherokee which is a light weight web server, fast and extremely simple to configure thanks to its great admin interface.The most common configuration to use cherokee with django is described here and to put is in a nutshell it was based on flup using SCGI or FASTCGI protocol.However a couple of weeks ago a new contender pop up on my radar. It is called uWSGI and it might become in the near future very popular to power django application. You can find more information about it on on the pages below :* example [2]* Documentation [3]From an architecture stand point it might provide us python web developer an interesting piece of software that could operate with virtually any webserver. There is already an apache module and cherokee handler. The documentation mentions that the core developers have started to develop an nginx adaptor.Software prerequisites cherokee 0.99.26uWSGI (changeset: 85:61dcfd718023)I have installed cherokee using the PPA on launchpad [1] and uWSGI directly from the mercurial repository.hg clone http://projects.unbit.it/hg/uwsgiInstallationInstallation of both product is relatively straight forward and well documented. I will not detail it more here but rather point you to cherokee [4] and uWSGI … -
Lessons from Rackspace's downtime
Last night Rackspace Cloud had some downtime. Reading post-mortems is always instructive, so let’s see what we can learn from Rackspace. It sounds like this downtime was caused by a power issue: We were testing phase rotation on a Power Distribution Unit (PDU) when a short occurred and caused us to lose the PDUs behind this Cluster. The phase rotation allows us to verify synchronization of power between primary and secondary sources. -
Describing Relationships: Django's ManyToMany Through
How to implement many-to-many relationships with extra fields, or, Many-to-Many Through. Covers django models and admin. -
Describing Relationships: Django's ManyToMany Through
In this post I'll describe extending many-to-many relationships in Django to support additional columns on the junction table. I'll be using the following table structure as the starting place. Imagine an RSS aggregator consisting of feeds, articles and categories. Articles come from a feed and may belong to any number of categories. Suppose I wanted to implement a white-listing feature, wherein articles would only get added to categories if they matched a list of keywords assigned to that category. This is a good time to use a many-to-many through relationship. The idea here is that we are describing the intersection of two objects: The intersection of feeds and categories contains an extra piece of data: which filter to apply to that feed before inserting articles into the category. Django Implementation Here is how the schema translates into Django model definitions: class Feed(models.Model): name = models.CharField(max_length=255) url = models.URLField() # Note the `through` keyword argument: categories = models.ManyToManyField(Category, through='FeedCategoryRelationship') source = models.ForeignKey(Source) last_download = models.DateField(auto_now=True) new_articles_added = models.PositiveSmallIntegerField(default=0, editable=False) active = models.BooleanField(default=True) ... class FeedCategoryRelationship(models.Model): feed = models.ForeignKey(Feed) category = models.ForeignKey(Category) white_list = models.ManyToManyField(WhiteListFilter, blank=True) ... Accessing related data is a snap: def perform_download(self): """Download articles associated with this feed""" for … -
Describing Relationships: Django's ManyToMany Through
In this post I'll describe extending many-to-many relationships in Django to support additional columns on the junction table. I'll be using the following table structure as the starting place. Imagine an RSS aggregator consisting of feeds, articles and categories. Articles come from a feed and may belong to any number of categories. Suppose I wanted to implement a white-listing feature, wherein articles would only get added to categories if they matched a list of keywords assigned to that category. This is a good time to use a many-to-many through relationship. The idea here is that we are describing the intersection of two objects: The intersection of feeds and categories contains an extra piece of data: which filter to apply to that feed before inserting articles into the category. Django Implementation Here is how the schema translates into Django model definitions: class Feed(models.Model): name = models.CharField(max_length=255) url = models.URLField() # Note the `through` keyword argument: categories = models.ManyToManyField(Category, through='FeedCategoryRelationship') source = models.ForeignKey(Source) last_download = models.DateField(auto_now=True) new_articles_added = models.PositiveSmallIntegerField(default=0, editable=False) active = models.BooleanField(default=True) ... class FeedCategoryRelationship(models.Model): feed = models.ForeignKey(Feed) category = models.ForeignKey(Category) white_list = models.ManyToManyField(WhiteListFilter, blank=True) ... Accessing related data is a snap: def perform_download(self): """Download articles associated with this feed""" for … -
Describing Relationships: Django's ManyToMany Through
In this post I'll describe extending many-to-many relationships in Django to support additional columns on the junction table. I'll be using the following table structure as the starting place. Imagine an RSS aggregator consisting of feeds, articles and categories. Articles come from a feed and may belong to any number of categories. Suppose I wanted to implement a white-listing feature, wherein articles would only get added to categories if they matched a list of keywords assigned to that category. This is a good time to use a many-to-many through relationship. The idea here is that we are describing the intersection of two objects: The intersection of feeds and categories contains an extra piece of data: which filter to apply to that feed before inserting articles into the category. Django Implementation Here is how the schema translates into Django model definitions: class Feed(models.Model): name = models.CharField(max_length=255) url = models.URLField() # Note the `through` keyword argument: categories = models.ManyToManyField(Category, through='FeedCategoryRelationship') source = models.ForeignKey(Source) last_download = models.DateField(auto_now=True) new_articles_added = models.PositiveSmallIntegerField(default=0, editable=False) active = models.BooleanField(default=True) ... class FeedCategoryRelationship(models.Model): feed = models.ForeignKey(Feed) category = models.ForeignKey(Category) white_list = models.ManyToManyField(WhiteListFilter, blank=True) ... Accessing related data is a snap: def perform_download(self): """Download articles associated with this feed""" for … -
Describing Relationships: Django's ManyToMany Through
In this post I'll describe extending many-to-many relationships in Django to support additional columns on the junction table. I'll be using the following table structure as the starting place. Imagine an RSS aggregator consisting of feeds, articles and categories. Articles come from a feed and may belong to any number of categories. Suppose I wanted to implement a white-listing feature, wherein articles would only get added to categories if they matched a list of keywords assigned to that category. This is a good time to use a many-to-many through relationship. The idea here is that we are describing the intersection of two objects: The intersection of feeds and categories contains an extra piece of data: which filter to apply to that feed before inserting articles into the category. Django Implementation Here is how the schema translates into Django model definitions: class Feed(models.Model): name = models.CharField(max_length=255) url = models.URLField() # Note the `through` keyword argument: categories = models.ManyToManyField(Category, through='FeedCategoryRelationship') source = models.ForeignKey(Source) last_download = models.DateField(auto_now=True) new_articles_added = models.PositiveSmallIntegerField(default=0, editable=False) active = models.BooleanField(default=True) ... class FeedCategoryRelationship(models.Model): feed = models.ForeignKey(Feed) category = models.ForeignKey(Category) white_list = models.ManyToManyField(WhiteListFilter, blank=True) ... Accessing related data is a snap: def perform_download(self): """Download articles associated with this feed""" for … -
The power of "no"
The power of “no” Last week, I wrote on Twitter: Closed-source software gets worse with each release (Microsoft, Adobe, …). Open-source software gets better (OOo, Ubuntu, …). Discuss. Much interesting discussion did ensue – mostly around the exceptions (Apple, Google). However, I’m less interesting in the exceptions than I am in the general rule. Sure, you can find plenty of examples of commercial software that’s improving over time, and, yes, there’s plenty of open source software that suffers from bloat and creeping features. -
A BeautifulSoup with Django and Pygments
Just added syntax highlighting using BeautifulSoup and Pygments. I took the SaltyCrane Blog for inspiration, but in contrast to it, I implemented it as a template filter in a separate application. This is surely not the most performant way, but I’m planning to use memcache, so I think this is ok. Here an example how to use the filter: {% load highlight_code %} {{ my_var_with_code|highlight|safe }}