Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
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 }} -
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 }} -
SEO scumbags
Please die in a fire: From: <…@hootsmart.com> Subject: I would like to offer free SEO for the djangoproject.com Hi Jacob, I would like to offer my SEO services free of charge for the djangoproject and in return to have a link from the djangoproject.com web page to my own site. 1. I Would like to contribute free SEO advice to the project ( could write a paper on SEO techniques). -
New Project: Telvee
I have been working on telvee for a few months. To be precise gitk tells the initial commit was at 2009-06-24 16:20:38. I have been meaning to write about it but just couldn’t find the time (or should I say couldn’t drag my lazy ass to do it). Anyway. I have marked version 0.3 for [...] -
Recovery.gov Augmented Reality Mashup
As of today Android and iPhone 3GS users can see recovery.gov contract data on their phones via the Layar augmented reality application. Layar is an application that overlays your view of the real world with waypoints representing your favorite coffee place, the movie theatre you're trying to find, or in this case, where some of that $787 billion from the American Recovery and Reinvestment Act is going. If you have an iPhone 3GS or Android device you can install the Layar app for free and then search for "recovery" or "sunlight" within Layar to find this layer. The layer works best near large cities where you are most likely to find recovery contracts, below is an example of what it looks like on the streets of Washington DC. There are also a few options to help you filter the results should you be in a contract-heavy area like DC, it is possible to filter by amount or search by name if you're trying to find larger contracts or contracts for a certain nearby recipient. This data is taken from the recovery.gov Where Is The Money Going? map which provides a KML file containing all recipient reported Contracts. As of October … -
South 0.6.2
In my neverending quest to save the time of those using RDBMSen, South 0.6.2 is released. It mostly contains bugfixes, but there's now support for extending introspection to third-party apps without having to edit their source. I'll probably start working full steam on South 0.7 soon - there's a refactor of the migration engine (mostly done), of startmigration (not started), and a few changes to command names to make them nicer (the old ones will still work), and to the behaviour of default values. I'm hoping 0.7 will be the last release before 1.0, at which point I will claim I've been working in an octal version numbering sequence all along. -
django-piston authentication against django auth -- part 4
The previous post ends with one known "Open Issue". The authentication for the ajax call was sitll hard coded [1]. In this post I am going to show you how you can extend django-piston to authenticate your users against django.contrib.auth. This might be important if your web app already take advantage of this module to manage and authenticate users.A bit of reading of the source code and the documentation of django-piston [2] leads me to understand that django-piston has been designed from the ground to enable you to easily write your own authentication handler. Out of the box it comes with "HttpBasicAuthentication" and OAuthAuthentication. "HttpBasicAuthentication" is a very good example how to implement a DjangoAuthentication.An authentication handler is a class, which must have 2 methods: is_authenticated, challengeclass DjangoAuthentication(object): """ Django authentication. """ def __init__(self, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME): if not login_url: login_url = settings.LOGIN_URL self.login_url = login_url self.redirect_field_name = redirect_field_name self.request = None def is_authenticated(self, request): """ This method call the `is_authenticated` method of django User in django.contrib.auth.models. `is_authenticated`: Will be called when checking for authentication. It returns True if the user is authenticated False otherwise. """ self.request = request return request.user.is_authenticated() def challenge(self): """ `challenge`: In cases where `is_authenticated` returns False, … -
Talented front-end developer job for Web 2.0 company in Oxford
The company I work for, 2Degrees, is looking for a front-end developer to join our team. Are you a CSS monkey? We need a CSS monkey with a good working knowledge of browser quirks and the ability to get even IE6 looking good (although you don't have to like it). It would help if you don't run away screaming from Javascript and can play well with the code monkeys. More details are below. Email the address at the bottom of the job description, and mention this blog! -
Talented front-end developer job for Web 2.0 company in Oxford
The company I work for, 2Degrees, is looking for a front-end developer to join our team. Are you a CSS monkey? We need a CSS monkey with a good working knowledge of browser quirks and the ability to get even IE6 looking good (although you don't have to like it). It would help if you don't run away screaming from Javascript and can play well with the code monkeys. More details are below. Email the address at the bottom of the job description, and mention this blog! Job Description Would you like to do something genuinely useful with your client side development skills - UI, XHTML, CSS (JavaScript, AJAX) 2degrees is an exciting, fast-paced, well-funded Web2.0 environmental networking business based in Oxford. We're looking for a top-notch client-side developer eager to work with our talented team to evolve our django-based Web2.0 application to meet the demands of our members and corporate partners (Cisco, EDF, British Gas, IBM) 2degrees’ purpose is to accelerate the speed at which businesses are able to implement sustainability and carbon reduction strategies on a global scale. Our members include sustainability professionals from companies such as HSBC, Coca-Cola, BASF, Sony, Marks & Spencer, BP, Shell, Eurostar, Sainsbury’s, … -
Talented front-end developer job for Web 2.0 company in Oxford
The company I work for, 2Degrees, is looking for a front-end developer to join our team. Are you a CSS monkey? We need a CSS monkey with a good working knowledge of browser quirks and the ability to get even IE6 looking good (although you don't have to like it). It would help if you don't run away screaming from Javascript and can play well with the code monkeys. More details are below. Email the address at the bottom of the job description, and mention this blog! Job Description Would you like to do something genuinely useful with your client side development skills - UI, XHTML, CSS (JavaScript, AJAX) 2degrees is an exciting, fast-paced, well-funded Web2.0 environmental networking business based in Oxford. We're looking for a top-notch client-side developer eager to work with our talented team to evolve our django-based Web2.0 application to meet the demands of our members and corporate partners (Cisco, EDF, British Gas, IBM) 2degrees’ purpose is to accelerate the speed at which businesses are able to implement sustainability and carbon reduction strategies on a global scale. Our members include sustainability professionals from companies such as HSBC, Coca-Cola, BASF, Sony, Marks & Spencer, BP, Shell, Eurostar, Sainsbury’s, … -
Minimum cost for warming-up various frameworks(and more)
Minimum cost for warming-up various frameworks(and more) -
Weather App on Github
As promised, I put the code of the climate_change app online. For that reason, I created an account on github trying to use Git for the first time. This is also the first time I am using a distributed version control system, i.e. you can create branches of the project, develop the forks separately on different computers, and merge them in any order. There is no main centralized repository. The code on github that I uploaded is just one initial copy.I am still new to Git commands and workflows. You can share your knowledge with me. For example, maybe you know some good cheat sheet or writings about Git. Or you can try to fork the project I committed, change it somehow and then push for merging (not sure if I'm using correct jargon). I will share with you what I find interesting and useful about Git while learning it. -
QFT
Daniel Dvorkin: In every field which was once exclusively male, but is now no longer, it’s been claimed first, that no woman can perform alongside men; second, when the first claim is disproven, that hardly any woman can; and third, when the second claim is disproven, that maybe a few women can, but a majority lack the ability or the inclination. And every single time, as the residual sexism fades, the third claim is shown to be false as well. -
More Feeds
Just added Atom Feeds for post categories and post comments. They are available in the category detail and post detail views. -
More Feeds
Just added Atom Feeds for post categories and post comments. They are available in the category detail and post detail views.