Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Damn foreign keys, stealing our jobs and women
Django has support for Generic Foreign Keys, which let you reference one model instance from another, without knowing up-front what that model type is. The classic use for something like this is for a commenting system; you need generic foreign keys – or something like them – because you wouldn't want a commenting system that only worked with a single model. If you have ever used generic foreign keys in Django, you will know that it is not quite transparent to the developer; a little effort is required to manage the various content types. I'll present here an alternative method to achieve this late binding of foreign keys that doesn't require storing the type of the object (as generic foreign keys do) and is completely transparent to the developer. I'm sure I'm not the first to think of this method, but I haven't yet seen it used in other Django projects. Rather than store the type of object in a separate field, we can create a new model for each foreign key type we want to reference. For example; lets say we have a Rating model, and we want to rate Articles and Images – we could do this by … -
Damn foreign keys, stealing our jobs and women
Django has support for Generic Foreign Keys, which let you reference one model instance from another, without knowing up-front what that model type is. The classic use for something like this is for a commenting system; you need generic foreign keys – or something like them – because you wouldn't want a commenting system that only worked with a single model. If you have ever used generic foreign keys in Django, you will know that it is not quite transparent to the developer; a little effort is required to manage the various content types. I'll present here an alternative method to achieve this late binding of foreign keys that doesn't require storing the type of the object (as generic foreign keys do) and is completely transparent to the developer. I'm sure I'm not the first to think of this method, but I haven't yet seen it used in other Django projects. Rather than store the type of object in a separate field, we can create a new model for each foreign key type we want to reference. For example; lets say we have a Rating model, and we want to rate Articles and Images – we could do this by … -
The Mess Django’s In?
In the Mock It! blog, Malthe Borch writes that Django’s innards are a disaster. The comments are as good as the article. Money quote: [If you] take a peek under the hood, your impression of Django will change dramatically: The code is awful. [Django's] got a terrific story if you’re willing to drink the kool-aid [...] -
My Idea Of The Django Blogging App™
I am not going to talk about yet another Django-based blogging engine in this post. There are a number of blogging apps which try to be like turn-key solutions, like a WordPress blog. I have skimmed through the code of many such apps, but haven’t used one yet. Some of them are really high quality [...] -
Optimizing Django: tricks for faster page loads
By reducing the file size of your CSS, JavaScript and images, as well as the number of unnecessary browser requests made to your site, load time of your applications pages can be drastically reduced, not to mention the load on your server. Yahoo have created a list of the 35 best practices to speed up your website, a recommended read for any web developer. I wanted to summarize a few I recently implemented in a Django application. In a nutshell: Serve compressed static media files. This one is obvious, the smaller the file size, the quicker it is to download. Once a browser has already downloaded the static media, it shouldn't have to download it again. This is what actually happens, as the server will respond with 304 Not Modified, which means that the cached file is still up-to-date. However, the HTTP request is still sent. This is unnecessary and should be avoided by setting the HTTP Expire header to a date in the future. When files are updated, you need to give them a new URL so the browser will request them. This is referred to as versioning. A common scheme is to use the modification time/date of the … -
Optimizing Django: tricks for faster page loads
By reducing the file size of your CSS, JavaScript and images, as well as the number of unnecessary browser requests made to your site, load time of your applications pages can be drastically reduced, not to mention the load on your server. Yahoo have created a list of the 35 best practices to speed up your website, a recommended read for any web developer. I wanted to summarize a few I recently implemented in a Django application. In a nutshell: Serve compressed static media files. This one is obvious, the smaller the file size, the quicker it is to download. Once a browser has already downloaded the static media, it shouldn't have to download it again. This is what actually happens, as the server will respond with 304 Not Modified, which means that the cached file is still up-to-date. However, the HTTP request is still sent. This is unnecessary and should be avoided by setting the HTTP Expire header to a date in the future. When files are updated, you need to give them a new URL so the browser will request them. This is referred to as versioning. A common scheme is to use the modification time/date of the … -
Optimizing Django: tricks for faster page loads
By reducing the file size of your CSS, JavaScript and images, as well as the number of unnecessary browser requests made to your site, load time of your applications pages can be drastically reduced, not to mention the load on your server. Yahoo have created a list of the 35 best practices to speed up your website, a recommended read for any web developer. I wanted to summarize a few I recently implemented in a Django application. In a nutshell: Serve compressed static media files. This one is obvious, the smaller the file size, the quicker it is to download. Once a browser has already downloaded the static media, it shouldn't have to download it again. This is what actually happens, as the server will respond with 304 Not Modified, which means that the cached file is still up-to-date. However, the HTTP request is still sent. This is unnecessary and should be avoided by setting the HTTP Expire header to a date in the future. When files are updated, you need to give them a new URL so the browser will request them. This is referred to as versioning. A common scheme is to use the modification time/date of the … -
Announcing django-audit
As part of some work at 2degrees on ensuring an audit trail for our Django models, we have been working on a project to add under-the-hood auditing to the Django Model class.We've published an early alpha of this code on launchpad, and hope to have a final release for this package around the end of May to coincide with the deployment of our internal code.If you can't wait for the documentation, then checkout the code and have a read of the source. Otherwise documentation will be coming along shortly. -
GSOC 2010 – I’m updating the Django Test Suite
I’ve been accepted to work on Django’s Test Suite during the Google Summer of Code this year. I’ll be working to improve the runtime and uniformity of the test suite, mainly by converting existing doc tests to unit tests. This isn’t particularly glamorous, but it should be a chance to get intimately familiar with the [...] -
Primeiro projeto com Python, Django e MongoDB
Estou desde o começo deste ano acompanhando o hype dos bancos de dados orientados a documento, também chamado de NoSQL (embora não goste muito deste termo). Como bom curioso, resolvi testar algumas variações como o CouchDB e MongoDB, onde acabei me identificando mais com o segundo. Gostei da praticidade e rapidez em fazer as coisas com ele, também a performance me chamou muito a atenção, tem uma boa biblioteca Python e a documentação é muito objetiva, com exemplos de uso. Esses pontos foram decisivos para a escolha. Com um banco de dados orientado a documentos, não existe a necessidade de criar o modelo das tabelas, basta definir um documento (estilo JSON) e inserir na base. Esses documentos podem ter campos a mais ou a menos dependendo da necessidade e tudo pode ser indexado e encontrado facilmente. Estou trabalhando em um projeto onde é necessário indexar uma grande quantidade de informações e documentos. O problema é que muitos documentos não seguem um padrão e existe a necessidade de estar alimentando a base a todo instante com novas informações. Já desenvolvi modelos de busca neste estilo utilizando o Xapian, que é uma excelente ferramenta. Porém a performance fica bastante prejudicada quando a … -
Django Model Templates (sans-Denormalisation)
I came across an interesting problem recently, while trying to model the structure of a university course in Django. The model needed to represent the notion of a university module, which can be taught over a number of semesters and/or years, by different people, and with different students each time round. Some information remained common [...] -
Official nonrel/NoSQL support in Google Summer of Code!
This is great news for Django developers who want to use non-relational DBs: Alex Gaynor got accepted for adding non-relational DB support to Django's ORM during Google Summer of Code! This means that we now have to make sure that the ORM changes are flexible enough to build a common API for all nonrel DBs, so code can be reused everywhere without any modifications (or, at least between DBs with similar capabilities). Once we have official nonrel support in Django we can move on to the next phase of Django-nonrel: building an indexing layer which supports denormalization and many other features that go beyond the DB's native capabilities and which you'd normally implement by hand. This topic has been discussed in the recent DjangoDose NoSQL panel and you surely noticed how controversial it is. Well, we don't have to decide which solution is the best one - both have their pros and cons. Instead, our planned Django-nonrel indexing layer can be an optional package (outside of Django core) that you can use on top of the low-level backend if you want more productivity, at the cost of having to understand what the technical limitations behind this method are (they're the … -
De retour de Djangocong
Les rencontres Django francophones 2010, tenues à Marseille, viennent de s’achever. David Larlet m’ayant invité à y participer, j’y ai présenté une conférence “Django pour les développeurs Symfony” puisqu’étant moi-meme utilisateur des deux frameworks. Vous trouverez les slides de la présentation sur slideshare, ou sur la page dédiée à Django sur le site d’Akei. N’hésitez pas à faire vos retours en commentaire. -
Our New Open-source Projects
Apart from GLAMkit, we have rarely mentioned our open-source projects. I wanted to quickly show three which were recently open-sourced by IxC contractors in the course of their work for us: django-nose-lite, by howthebodyworks - a lightweight nosetests runner for Django projects. My favourite is to run it with —pdb, which drops into pdb on test failures. django-smuggler, by semente is fairly simple. It adds a button to Django’s admin interface which dumps and loads fixtures to your (local) computer - for superusers only. django-hashtags, also by semente, converts Twitter-esque #hashtags in text fields into a link to search for items with those hashtags - recent tweets included. Feel free, of course, to reuse, fork and contribute changes. There are more releases in the works. -
A handful of snippets
A collection of a few snippets I've made use of recently. -
MyUni and Django 1.2
MyUni is hailed as my "latest venture" on the front page of my website. In fact, it was conceived early last year, when I was in my first year at Nottingham University, by Rob Miles and Ben Jenkinson. We were only just starting to get to grips with this new fad, called Django. The project [...] -
Moving away from DC
Way back in 1969, when I was about a year and a half old, my family moved to Laurel, Maryland, which is about 20 miles north of Washington, DC. Since then, I've lived in central Maryland, Washington, and Northern Virginia. I enjoyed my friends and family, and the things that I've done.Yet I always wanted to see the rest of our world, try new things, explore new horizons. Breathe different air, if you will. My ideal existence would be to live in a lot of different places, living six months for a time in place to place so I can get a good experience of the planet.Not long ago conditions came together that made it feasible for me to do all this. My house is sold, my son is 18, I don't currently own any furniture, and I have a job that allows/encourages for telecommuting (and that is because of Python and Django). So on May 5th I'm moving to Los Angeles, California for a short term stay. I'm there to hang out with a certain artist/developer and to go on a vacation that I've wanted to do for many months. More details on this move in another post.In early … -
Fashiolista.com – Django at The Next Web – part 1
Fashiolista.com is launching in 7 days and has already been getting quite some attention. Techcrunch: 25 startups that will be shaping the next web. For Fashiolista we’ve been able to utilize a great deal of best practises learned in previous Django based sites. More on this topic later. For now I’m wondering if there are many other Django fans attending the next web conference. The conference itself should be very interesting. Definitely looking forward to Werner Vogels and Joe Stump. The later seems to be running Django for SimpleGeo. Share and Enjoy: -
Vim autocomplete, Django and virtualenv
One of the features I quite missed when I first moved from Komodo to Textmate as my main editor was autocompletion. Although I didn't use it very much, it was occasionally useful to be reminded of the methods available on a class, without having to look up the documentation or open the source module. Now I've moved to vim, which has its own version of autocomplete: omnicompletion. This is activated by pressing Ctrl-X Ctrl-O in insert mode after typing the name of a class or instance, and displays a nice drop-down menu with all the available members of that object. The Python plugins which come with vim allow this function to not only complete items from the standard library, but also to parse your own files which are open in the editor, reading the modules you import and adding those elements to the completion dictionaries. However, this wasn't working for me in my Django projects. After a lot of investigation, I found that this was down to three issues. The first two of these related to the fact that I was working within a virtualenv. Despite the fact that I was starting MacVim after activating the virtual environment, the specific … -
Vim autocomplete, Django and virtualenv
One of the features I quite missed when I first moved from Komodo to Textmate as my main editor was autocompletion. Although I didn't use it very much, it was occasionally useful to be reminded of the methods available on a class, without having to look up the documentation or open the source module. Now I've moved to vim, which has its own version of autocomplete: omnicompletion. This is activated by pressing Ctrl-X Ctrl-O in insert mode after typing the name of a class or instance, and displays a nice drop-down menu with all the available members of that object. The Python plugins which come with vim allow this function to not only complete items from the standard library, but also to parse your own files which are open in the editor, reading the modules you import and adding those elements to the completion dictionaries. However, this wasn't working for me in my Django projects. After a lot of investigation, I found that this was down to three issues. The first two of these related to the fact that I was working within a virtualenv. Despite the fact that I was starting MacVim after activating the virtual environment, the specific … -
Avoiding some generic views
As I wrote this, I realised I seemed to be on a roll with negative blog posts. Sorry, I will get positive again soon, I'm sure. If you follow through the Django tutorial, you'll get to stage 4 which encourages you to move to generic views. Generic views are a neat way of removing the view part of the equation. Instead of a standard URL > view > template, you have URL > template. There's documentation on all the generic views and there's quite a few. The problem Here's the conversation that goes on in #django IRC about once every day or so. Abbreviated, its normally more long winded than this. djangodood: can I pass parameters to a query in templates? others: no djangodood: well how do I do this then? I tried doing it in urls.py and that didn't work others: do it in your view ...usually a break of a few minutes. djangodood: but I want to use my generic views others bang heads on table Logic for a template should be done mostly in the view. If its very model specific, doing it in the model might make sense. But the key is keep the template as … -
Bye-bye django.comments, hello Disqus
So, I've learned my lesson. When I first set up this blog I said at great length that I'd prefer using Django's built-in commenting system than the third-party Disqus service that Mingus uses by default. Well, after a week of trying to stop a flood of spam comments, first by deleting them as they came in and then by disabling comments altogether, I've taken the plunge and reverted my changes, so I'm now incorporating Disqus. All the (13!) real existing comments have been ported over to Disqus. For those who are interested, copying the comments over was surprisingly simple. I thought I'd have to create some XML to import them into Disqus, but it turns out there is a nice API. It further turns out that the django-disqus app includes a simple management command, disqus-export, which copies the comments straight over. One issue - the fork of this app included in Mingus has some issues with this command on recent Django versions, but you just need to remove the verbosity option in the script to make it work. -
Quelques retours post-lancement
Soyons honnêtes, je ne pensais pas écrire un second billet aussi vite, a fortiori dans la langue de Molière. Mais le feedback a été tellement enthousiasmant que je me sens presque obligé d’apporter quelques réponses à des questions qui m’ont été posées, le plus souvent en privé, à propos du site et de sa genèse. Sur le design La conception graphique n’est pas de moi ; c’est un template que j’ai acheté sur ThemeForrest, « Logical » mais que j’ai entièrement recodé et aménagé en fonction des besoins particuliers de gestion de contenus qui étaient les miens (vous pouvez comparer les sources pour vous en convaincre.) Notez que je ne suis ni graphiste, ni webdesigner de formation, mais ingénieur de fait 1. Je suis personnellement assez satisfait d’avoir pu mettre en œuvre le résultat que vous avez sous les yeux, même si j’eu bien évidemment préféré avoir conçu la charte initiale par moi-même. Que voulez-vous, on ne peut exceller sur tous les fronts ; et l’une des compétences les plus indispensables pour faire face à ces lacunes à mes yeux est de toujours savoir déléguer opportunément. Dont acte. D’autre part, et c’est un retour qui m’a été fait de nombreuses … -
Bye-bye django.comments, hello Disqus
So, I've learned my lesson. When I first set up this blog I said at great length that I'd prefer using Django's built-in commenting system than the third-party Disqus service that Mingus uses by default. Well, after a week of trying to stop a flood of spam comments, first by deleting them as they came in and then by disabling comments altogether, I've taken the plunge and reverted my changes, so I'm now incorporating Disqus. All the (13!) real existing comments have been ported over to Disqus. For those who are interested, copying the comments over was surprisingly simple. I thought I'd have to create some XML to import them into Disqus, but it turns out there is a nice API. It further turns out that the django-disqus app includes a simple management command, disqus-export, which copies the comments straight over. One issue - the fork of this app included in Mingus has some issues with this command on recent Django versions, but you just need to remove the verbosity option in the script to make it work. -
NoSQL panel on DjangoDose
DjangoDose has published a "callcast" about NoSQL support in Django. It's pretty interesting to learn about the different views on how far support for non-relational (NoSQL) DBs should go. Alex Gaynor wants to work on NoSQL backend support during Google Summer of Code and if he gets accepted (which is very likely) we might get official non-relational DB support in Django 1.3! Let me quickly summarize the most important topics that came up: Some non-relational DBs only support primary key queries (i.e., you can't query by an attribute). The way developers work around this is that they manually maintain extra "index" tables where the primary key is the attribute value that you want to filter against (e.g., username) and another attribute in that table stores the corresponding primary key (e.g., user id). For example, an entry for the username index would look like this: {'pk': 'wkornewald', 'user_id': 1} One of the big questions was: Is it enough for Django to support pk-only queries or should Django (or some separate module) take care of maintaining indexes for you? Is the admin useful if you can only query by pk? Is it sufficient if you can only browse through your database (by …