Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Itchy Fingers
Last night after I got home from techmeetup I had itchy fingers, the domain transfer had finally came through so I went for it. I flipped the switch. My new website and sitesprint effort is now officially launched! I'll be doing a full post-mortem of the sitesprint development after its finished as I hope to do a few more final tweaks on things. Please let me know if you have any feedback or comments - I really appreciate and enjoy getting feedback from my visitors. -
South migrations with MPTT
We've been using django-MPTT at work for quite a while. It's a great way to manage hierarchical data in a read-efficient way, and we use it heavily in our CMS application. I'll definitely be talking about it further in future posts. Recently we moved our database migrations from our defunct dmigrations project to Andrew Godwin's wonderful South application. One of South's best features is the ability to 'freeze' the ORM within each migration, so that you can manipulate the db via the familiar Django syntax rather than having to deal with raw SQL. However, we ran into a problem when trying to use this to add new instances to a model that uses MPTT. We're actually using Ben Frishman's fork of django-mptt, which he wrote while he was working for us this summer. This has a base model class that defines all the MPTT fields and methods, rather than monkey-patching them in as the original version does. The issue was that the frozen ORM only includes the basic fields that are defined on the actual model. This led to trouble when inserting a new object, especially when it's in the middle of an existing tree. MPTT includes values which identify … -
South migrations with MPTT
We've been using django-MPTT at work for quite a while. It's a great way to manage hierarchical data in a read-efficient way, and we use it heavily in our CMS application. I'll definitely be talking about it further in future posts. Recently we moved our database migrations from our defunct dmigrations project to Andrew Godwin's wonderful South application. One of South's best features is the ability to 'freeze' the ORM within each migration, so that you can manipulate the db via the familiar Django syntax rather than having to deal with raw SQL. However, we ran into a problem when trying to use this to add new instances to a model that uses MPTT. We're actually using Ben Frishman's fork of django-mptt, which he wrote while he was working for us this summer. This has a base model class that defines all the MPTT fields and methods, rather than monkey-patching them in as the original version does. The issue was that the frozen ORM only includes the basic fields that are defined on the actual model. This led to trouble when inserting a new object, especially when it's in the middle of an existing tree. MPTT includes values which identify … -
Customising Mingus, part 2
This is intended to be primarily a technical blog, so I was keen to get the presentation of code snippets correct. I'm a - shall we say - fairly frequent answerer on StackOverflow, and I've got used to their Markdown-enabled edit box. Luckily, the Mingus basic-blog application allows a choice of markup for body text, and even defaults to Markdown. But as always there were quite a few things to improve. Firstly, I do like StackOverflow's dynamic WYSIWSYG preview of the marked-up copy. Although Markdown syntax is quite simple, it's easy to get it wrong - using a three-space indent rather than four for code, for example. An instant preview just underneath the text entry field in the admin form is very useful. SO does it using the showdown.js library, which is part of their port of the 'what you see is what you mean' markdown editor, WMD. It was as easy to integrate the whole of WMD as just the preview, by adding a mingus\admin.py like this: from django import forms from django.conf import settings from django.contrib import admin from django.utils.safestring import mark_safe from basic.blog.models import Post from basic.blog.admin import PostAdmin class WMDEditor(forms.Textarea): def __init__(self, *args, **kwargs): attrs = … -
Customising Mingus, part 2
This is intended to be primarily a technical blog, so I was keen to get the presentation of code snippets correct. I'm a - shall we say - fairly frequent answerer on StackOverflow, and I've got used to their Markdown-enabled edit box. Luckily, the Mingus basic-blog application allows a choice of markup for body text, and even defaults to Markdown. But as always there were quite a few things to improve. Firstly, I do like StackOverflow's dynamic WYSIWSYG preview of the marked-up copy. Although Markdown syntax is quite simple, it's easy to get it wrong - using a three-space indent rather than four for code, for example. An instant preview just underneath the text entry field in the admin form is very useful. SO does it using the showdown.js library, which is part of their port of the 'what you see is what you mean' markdown editor, WMD. It was as easy to integrate the whole of WMD as just the preview, by adding a mingus\admin.py like this: from django import forms from django.conf import settings from django.contrib import admin from django.utils.safestring import mark_safe from basic.blog.models import Post from basic.blog.admin import PostAdmin class WMDEditor(forms.Textarea): def __init__(self, *args, **kwargs): attrs = … -
DjangoSki Registration is now open
Registration is now open for DjangoSki. Early bird tickets are on a simple first come, first served basis and registration is here. With our three keynotes set up and all the hairy contracts signed away, all that's left for us to do is plan the rest of the conference. And let it snow, snow and snow so that we've got a good base of snow ready for the conference. The next date to worry about is in about 3 weeks time, which is the deadline for any scheduled talks. We've got a couple of interesting case study talks lined up and still looking for some good introductory talks eg: Introduction to Django, Pinax, Django-CMS and so on. Been putting quite a few posts about DjangoSki up, sorry about that. It's very exciting for me and been quite a bit of work. Normal business of ignoring the blog and going back to Twitter will resume shortly. -
Python metaclasses and how Django uses them
Foss.in is without doubt India’s largest FOSS technology conference. Lakshman gave a talk today on “Python metaclasses and how Django uses them”. Here are the slides from that talk. Doing magic with python metaclassesView more documents from Usware Technologies. [Edit] Some reactions, http://twitter.com/jaideep2588/status/6295483833 http://twitter.com/kunalbharati/status/6296572939 And the talk images, http://twitpic.com/rxhn7 You should follow us on twitter [...] Related posts:The magic of metaclasses in Python Beginning python Better Python package management using source and version control systems -
Django quiz
A quick django quiz. Answers available tomorrow. Get it as a text file (django-quiz) or on google docs or read below. ### Easy 1. You have a class defined as class Post(models.Model): name = models.CharField(max_length=100) is_active = models.BooleanField(default=False) You create multiple objects of this type. If you do Post.objects.get(is_active=False), what exceptions is raised? a. MultipleObjectsReturned [...] Related posts:Doing things with Django forms Understanding decorators Using subdomains with Django -
Project Documentation
Currently I am in the process of passing down my project to some juniors and I find the need to document it. Me being the lazy ass programmer that I am obviously started to look for something that would allow me to complete my documentation in as least steps and most painless way as possible. Found two main applications that I am using now:1. Sphinx -> For main documenting work.2. Happydoc -> For parsing and generating code documentation. Both are quite easy to use and allows documentation to be generated in various format, which includes latex, html or pdf. Nice thing is both supports rest type reStructured text formatting which I just absolutely adore and is great to work with. I am especially impressed with Sphinx and the beautiful documents generated by Sphinx, coming with it's own search and everything. It's just what the lazy programmer doctor ordered. I am still evaluating both of these programs and am still open to other choices but so far these fit the bill nicely. -
Matt Berg keynote, call for speakers for DjangoSki
For our final keynote I'm pleased to say that Matt Berg will be speaking at DjangoSki. Matt Berg is the ICT Coordinator on the Millenium Villages Project at Columbia University. As part of that project he's been building technical systems in developing countries. He's involved with RapidSMS and projects include work in Kenya, South Senegal, Malawi and Rwanda that help children with malaria and malnutrition. And it's all using open source software and Django. Not only does Matt do interesting work that is helping people right now, but he passionately believes that he can use Django and other technologies to make a difference. His passion and dedication is infectious, as you'll find out. We have room for other speakers at the conference, so we'd like to call for other speakers to submit proposals to speak at the conference. Please apply here or see details here. -
Smart URL Redirects in Django
While building ComicBinder‘s URLs, I wanted a way to differentiate a volume of a title other than one, and a printing of an issue other than one. So, for example, a URL to the second printing of the second volume of Amazing Spider-Man #1 would look like: /marvel/amazing-spider-man_2/1_2/ That’s easy enough with some URLconf wrangling. [...] -
Jacob Kaplan-Moss keynote at DjangoSki
We are excited to announce that Jacob Kaplan-Moss will be giving one of the keynote talks at DjangoSki. It's almost impossible to be around Django and not know who Jacob is. He's one of the original founders of Django, is on the foundation board, is the co-BDFL of Django and is the co-author of The Definitive Guide to Django. Let's face it, if it's got something to do with Django, Jacob has had some influence on it. Currently Jacob works at Revolution Systems where he gets to do lots more Django. After missing Jacob at DjangoCon in Portland, it will be certainly good to have him around in Whistler. Perhaps even get some sprinting on Django 1.2 (which will be out a few days after DjangoSki). Jacob writes a great blog and is a great speaker. -
uWSGI reaches the 0.9.3 Milestone
uWSGI project [1] reaches the 0.9.3 milestone. You can review the complete announcement [2] on the mailing list and download the code here [3]This new release brings some new exiting features :- Nginx 0.7.x module- configuration via python module- support (non-standard) for Python 3.x- Twisted client resource adapter- graceful restart of worker processes and hot-plug substitution/upgradeof the uWSGI server- shared memory area to share data between workers/processes- Tomcat handler- support for virtualenvIn this post [4] I have covered the usage of both the "configuration via a python module" and the "virtualenv support".uWSGI allows you to run your favorite wsgi application on top of prefered web server (apache, cherokee or nginx).[1] http://projects.unbit.it/uwsgi/[2] http://lists.unbit.it/pipermail/uwsgi/2009-November/000020.html[3] http://projects.unbit.it/downloads/uwsgi-0.9.3.tar.gz[4] http://yml-blog.blogspot.com/2009/11/setting-up-django-project-with-cherokee.html -
8 Books To Get A Developer For The Holidays
Send this to your significant other/parent/relative/friend so, instead of that sweater, you get one of these nuggets of awesome this Christmas. The Pragmatic Programmer: From Journeyman to Master Write better, cleaner, more maintainable code. Learn how to manage your projects and focus on shipping your product. With insight that covers the gamut of software development [...] Related posts:Be Language Agnostic – Solve the Problem! Deployment Using Capistrano / Webistrano via Rails / Phusion Passenger Django 1.0 Template Development: Sample Chapter “Serving Multiple Templates” -
Should you go with Google App Engine?
Recently I responded to the question on Stack Overflow about wether Google App Engine is worth it, over conventional hosting providers for typical databased-backed setup. I will not recite all the pros and cons of App Engine as I already did that in my answer, but I would like to focus on one interesting aspect of Google App Engine where it wins big time over conventional hosting approaches. In particular - the deployment process. Let's get started... Deploying on regular hosting environment How do you deploy a web application (like Django for example) to an Apache-backed hosting server? Well there are a few steps you have to take: FTP or SCP your applicaton to the server Replace the folder with the new folder Stop the server, services etc.. Start the server services etc... BONUS: Modify your databse schema Of course if you are proper developer you might simplify you deployment process and also make use of revision control system. You can also write a script to automate the deployment process, in particular for steps 3-5: Commit your code to revision control, possibly marking it with a tag for Release or Deployment. Log onto your producton server Check out the code … -
You Built a Metaclass for *what*?
Recently I had a bit of an interesting problem, I needed to define a way to represent a C++ API in Python. So, I figured the best way to represent that was one class in Python for each class in C++, with a functions dictionary to track each of the methods on each class. Seems simple enough right, do something like this: class String(object): functions = { "size": Function(Integer, []), }We've got a String class with a functions dictionary that maps method names to Function objects. The Function constructor takes a return type and a list of arguments. Unfortunately we run into a problem when we want to do something like this: class String(object): functions = { "size": Function(Integer, []), "append": Function(None, [String]) }If we try to run this code we're going to get a NameError, String isn't defined yet. Django models have a similar issue, with recursive foreign keys. Django's solution is to use the placeholder string "self", and have a metaclass translate it into the right class. Also having a slightly more declarative API might be nice, so something like this: class String(DeclarativeObject): size = Function(Integer, []) append = Function(None, ["self"])So now that we have a nice pretty … -
Getting Started with Testing in Django
Following yesterday's post another hotly requested topic was testing in Django. Today I wanted to give a simple overview on how to get started writing tests for your Django applications. Since Django 1.1, Django has automatically provided a tests.py file when you create a new application, that's where we'll start.For me the first thing I want to test with my applications is, "Do the views work?". This makes sense, the views are what the user sees, they need to at least be in a working state (200 OK response) before anything else can happen (business logic). So the most basic thing you can do to start testing is something like this: from django.tests import TestCase class MyTests(TestCase): def test_views(self): response = self.client.get("/my/url/") self.assertEqual(response.status_code, 200)By just making sure you run this code before you commit something you've already eliminated a bunch of errors, syntax errors in your URLs or views, typos, forgotten imports, etc. The next thing I like to test is making sure that all the branches of my code are covered, the most common place my views have branches is in views that handle forms, one branch for GET and one for POST. So I'll write a test like … -
Django and Python 3
Today I'm starting off doing some of the posts people want to see, and the number one item on that list is Django and Python 3. Python 3 has been out for about a year at this point, and so far Django hasn't really started to move towards it (at least at a first glance). However, Django has already begun the long process towards moving to Python 3, this post is going to recap exactly what Django's migration strategy is (most of this post is a recap of a message James Bennett sent to the django-developers mailing list after the 1.0 release, available here).One of the most important things to recognize in this that though there are many developers using Django for smaller projects, or new projects that want to start these on Python 3, there are also a great many more with legacy (as if we can call recent deployments on Python2.6 and Django 1.1 legacy) deployments that they want to maintain and update. Further, Django's latest release, 1.1, has support for Python releases as old as 2.3, and a migration to Python 3 from 2.3 is nontrivial. However, it is significantly easier to make this migration from Python … -
Why Meta.using was removed
Recently Russell Keith-Magee and I decided that the Meta.using option needed to be removed from the multiple-db work on Django, and so we did. Yesterday someone tweeted that this change caught them off guard, so I wanted to provide a bit of explanation as to why we made that change.The first thing to note is that Meta.using was very good for one specific use case, horizontal partitioning by model. Meta.using allowed you to tie a specific model to a specific database by default. This meant that if you wanted to do things like have users be in one db and votes in another this was basically trivial. Making this use case this simple was definitely a good thing.The downside was that this solution was very poorly designed, particularly in light on Django's reusable application philosophy. Django emphasizes the reusability of application, and having the Meta.using option tied your partitioning logic to your models, it also meant that if you wanted to partition a reusable application onto another DB this easily the solution was to go in and edit the source for the reusable application. Because of this we had to go in search of a better solution.The better solution we've … -
Splitting up Django models
Sometimes it makes sense to split up your Django models for a specific application across multiple files instead of having all of them in one models.py file. This allows for easier and simpler code organization and maintenance. Splitting up your models in Django is fairly simple, although it requires a few extra steps. In our example, [...] -
Django for a Rails Developer
This is not yet another Django vs Rails blog post. It is a compilation of notes I made working with Django after having worked on Rails for years. In this post I want to give a brief introduction to Django project layout from a Rails developer point of view, on what is there, what is [...] Related posts:Rails and Django commands : comparison and conversion The Rails and Django models layer Rosseta stone Tools of Pro Django developer – aka What powers dinette and almost every app we write. -
Filing a Good Ticket
I read just about every single ticket that's filed in Django's trac, and at this point I'e gotten a pretty good sense of what (subjectively) makes a useful ticket. Specifically there are a few things that can make your ticket no better than spam, and a few that can instantly bump your ticket to the top of my "TODO" list. Hopefully, these will be helpful in both filing ticket's for Django as well as other open source projects.Search for a ticket before filing a new one. Django's trac, for example, has at least 10 tickets describing "Decoupling urls in the tutorial, part 3". These have all been wontfixed (or closed as a duplicate of one of the others). Each time one of these is filed it takes time for someone to read through it, write up an appropriate closing message, and close it. Of course, the creator of the ticket also invested time in filing the ticket. Unfortunately, for both parties this is time that could be better spent doing just about anything else, as the ticket has been decisively dealt with plenty of times.On a related note, please don't reopen a ticket that's been closed before. This one depends … -
Javascript inline forms outside of contrib.admin
This recipe follows on from the last two and shows how to do the addition of inline fields to a model form, outside of contrib.admin. -
What apps do I use?
I've been asked by a few people what apps am I going to use for this website. I'll probably go into some of them in a bit more detail at some point. However, I thought for those that are interested I would quickly dump my pip requirements.txt here. Django==1.1.1 Markdown==2.0.3 MySQL-python==1.2.3c1 #PIL==1.1.6 Pygments==0.10 South==0.6.2 Sphinx==0.5.2 django-tagging==0.3 docutils==0.5 oauth==1.0.1 simplejson==2.0.9 sorl-thumbnail==3.2.5 textile==2.1.3 twisted wsgiref==0.1.2 html5lib==0.11.1 pisa==3.0.32 django-debug-toolbar==0.8.1 django-vcs==0.1 django-disqus==0.2 http://effbot.org/downloads/Imaging-1.1.6.tar.gz http://www.reportlab.org/ftp/ReportLab_2_3.tar.gz -e git+git://github.com/dustin/twitty-twister.git#egg=twittywtister -e git+git://github.com/montylounge/django-basic-apps.git#egg=basic That gives you quite a good idea about what I'm using. It also maybe gives away some of the features I'm planning... well, a hint or two perhaps! -
A Bit of Benchmarking
PyPy recently posted some interesting benchmarks from the computer language shootout, and in my last post about Unladen Swallow I described a patch that would hopefully be landing soon. I decided it would be interesting to benchmarks something with this patch. For this I used James Tauber's Mandelbulb application, at both 100x100 and 200x200. I tested CPython, Unladen Swallow Trunk, Unladen Swallow Trunk with the patch, and a recent PyPy trunk (compiled with the JIT). My results were as follows:100CPython 2.6.4 17sUnladen Swallow Trunk 16sUnladen Swallow Trunk + Patch 13sPyPy Trunk 10s200CPython 2.6.4 64sUnladen Swallow Trunk 52sUnladen Swallow Trunk + Patch 49sPyPy 46sInteresting results. At 100x100 PyPy smokes everything else, and the patch shows a clear benefit for Unladen. However, at 200x200 both PyPy and the patch show diminishing returns. I'm not clear on why this is, but my guess is that something about the increased size causes a change in the parameters that makes the generated code less efficient for some reason.It's important to note that Unladen Swallow has been far less focussed on numeric benchmarks than PyPy, instead focusing on more web app concerns (like template languages). I plan to benchmark some of these as time goes on, …