Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Showing queries in Haystack
At work we've been using Haystack to manage our site search, with a Solr backend. As usual, we're customising things quite a lot - using faceted queries and weighted indexes, and bypassing the built-in search forms - so I wanted to be sure, in line with my general obsession with query efficiency, that we weren't generating multiple Solr queries for every search. Haystack does log queries for every request internally, but as far as I can tell there's no way of getting to that information without writing some custom code to import and expose the relevant variable. So I've written a (very basic) panel for the Django debug toolbar which does just that. Just put this somewhere on your pythonpath or in your project, and add it to the DEBUG_TOOLBAR_PANELS list in settings.py. -
Showing queries in Haystack
At work we've been using Haystack to manage our site search, with a Solr backend. As usual, we're customising things quite a lot - using faceted queries and weighted indexes, and bypassing the built-in search forms - so I wanted to be sure, in line with my general obsession with query efficiency, that we weren't generating multiple Solr queries for every search. Haystack does log queries for every request internally, but as far as I can tell there's no way of getting to that information without writing some custom code to import and expose the relevant variable. So I've written a (very basic) panel for the Django debug toolbar which does just that. Just put this somewhere on your pythonpath or in your project, and add it to the DEBUG_TOOLBAR_PANELS list in settings.py. -
integrated project management for development
Ironically, the choices for an in-house integrated project management toolchain are, to my mind, significantly more limited than the straight up open-source market. I have been looking and watching several projects over the past months for something that I could … Continue reading → -
New localization system already in trunk
Just few hours ago, Django's new localization system has been commited to trunk.As some of you know, I did most of the work as my Google Summer of Code project, this year. Of course, together with Jannis Leidel, who also did the final steps, including the commit.Summarizing, with this change Django will format all displayed data, according to user's current locale. For example, the calendar will display Sunday as the first day for users in the States, but Monday for users from most European countries. Also it'll format numbers and dates.You can check the slides I presented at DjangoCon.http://docs.google.com/present/view?id=dfbzs3ks_16d26xjbd9Note that the setting is no longer USE_FORMAT_I18N (as in the slides), but USE_L10N.You can also check the commit at:http://code.djangoproject.com/changeset/11964 -
Django Desktop
I implemented a theme system for locidesktop.com and thought it only fitting that the first theme I made was one for Django. I present you with the Django themed Loci Desktop! Here it is, in embedded form – although you really need to click the above link to fully appreciate it. -
Django Desktop
I implemented a theme system for locidesktop.com and thought it only fitting that the first theme I made was one for Django. I present you with the Django themed Loci Desktop! Here it is, in embedded form – although you really need to click the above link to fully appreciate it. -
Django Desktop
I implemented a theme system for locidesktop.com and thought it only fitting that the first theme I made was one for Django. I present you with the Django themed Loci Desktop! Here it is, in embedded form – although you really need to click the above link to fully appreciate it. -
Django patterns: memoizing
One of the things I wanted to do with this blog was to cover some of the design patterns I've discovered/come across/stolen over the years I've been working with Django. So this is the first in what I hope will be a long-running series on Django patterns. Memoizing is the process by which a complicated or expensive function is replaced by a simpler one that returns the previously calculated value. This is a very useful thing to do in a complicated model, especially in cases where methods like get_absolute_url are calculated via a series of lookups on related models. Frequently I've found myself calling one of these methods on the same object several times within a view or template, leading to a huge amount of unnecessary database calls. It's very easy to do this manually - the method simply needs to check whether the cached value already exists, if not calculate it and store it somewhere, then return the cached value: def get_expensive_calculation(self): if not hasattr(self, '_expensive_calculation'): self._expensive_calculation = do_expensive_calculation() return self._expensive_calculation Here the cache lives within the instance itself. For the way I use it, this is useful: instances are created and destroyed within a single request/response cycle, so … -
Django patterns: memoizing
One of the things I wanted to do with this blog was to cover some of the design patterns I've discovered/come across/stolen over the years I've been working with Django. So this is the first in what I hope will be a long-running series on Django patterns. Memoizing is the process by which a complicated or expensive function is replaced by a simpler one that returns the previously calculated value. This is a very useful thing to do in a complicated model, especially in cases where methods like get_absolute_url are calculated via a series of lookups on related models. Frequently I've found myself calling one of these methods on the same object several times within a view or template, leading to a huge amount of unnecessary database calls. It's very easy to do this manually - the method simply needs to check whether the cached value already exists, if not calculate it and store it somewhere, then return the cached value: def get_expensive_calculation(self): if not hasattr(self, '_expensive_calculation'): self._expensive_calculation = do_expensive_calculation() return self._expensive_calculation Here the cache lives within the instance itself. For the way I use it, this is useful: instances are created and destroyed within a single request/response cycle, so … -
Documentation for django-lastfm with django-sphinxdoc
Yesterday I finished a first version of django-sphinxdoc that integrates Sphinx documentation into a Django powered website. Its based on Django’s documentation app, but can manage the documenation for more then one app. I’ll post more on this later. What’s more important is, that I have put the documentation for django-lastfm online with it. :-) -
Documentation for django-lastfm with django-sphinxdoc
Yesterday I finished a first version of django-sphinxdoc that integrates Sphinx documentation into a Django powered website. Its based on Django’s documentation app, but can manage the documenation for more then one app. I’ll post more on this later. What’s more important is, that I have put the documentation for django-lastfm online with it. :-) -
Django-powered Snow
During the planning of our Christmas card at work this year, a mad idea came up. Do we ignore mad ideas? No, we tackle them head-on.The idea was to build an internet-controlled snow machine - you'd hit the button on the website, and watch a member of the Torchbox team get pelted with snow. When we first came up with the idea, we dismissed it as being "too complex", but after a while, we came around. Cue three days of frantic development and phoning round to get the parts. I'll be posting a full build article, with all our source code, once we're done. The brief summary is that we have a Django app which handles rate-limiting of snow, and tracking who has clicked the button, which then communicates with our snow machine using Artnet and DMX. Ustream is used to stream the video back to the internet. Still, I imagine you want to see it in action, so head over to snow.torchbox.com, and have a go. It's only online 10 - 5 UK time, and only until Tuesday (we can't fill our office up with paper snow forever), but it's still very good fun, even if you don't know … -
Test your django-piston API (with auth)
I have to build the API for one of my web service. It is Django and django-piston powered application and it works well. Okay. I chose the TDD technique. So my problem was: how do I test the API parts which need authentication (basic HTTP, not OAuth for now)? The built-in test client of Django doesn't seem to have such a feature. So, here is my small workaround: you have to generate the HTTP_AUTHORIZATION field of your HTTP request. I wrote a small base test class for tests which need authentication: You just have to replace username and password, and write your own test suite: It should be OK. Have fun! -
Nicer dynamic forms in django
I used to make dynamic forms for Django in very bad way, I'm happy to admit that now as I've improved my process. Basically the solution is to use type() as I'm sure many of you know. If your doing that already there isn't much for you here. If your messing around with 'self.fields["name"]' in your forms then read on. Lets take a simple use case; a quiz system. You can think of it like who wants to be a millionaire. We will have a Question with four possible answers. So two models... from django.db import models class Question(models.Model): test = models.CharField(max_length=128) class Answer(models.Model): question = models.ForeignKey(Question) test = models.CharField(max_length=20) is_correct = models.BooleanField(default=False) Basically we want a form that stores both the question and the answers and checks the answer is a valid choice. You could do it this way. from django import forms class QuizForm(forms.Form): def __init__(self,question, *args, **kwargs): super(QuizForm, self).__init__(*args, **kwargs) self.fields['question'] = forms.IntegerField(widget= \ forms.HiddenInput, initial=question.id) self.fields['answers'] = forms.ModelChoiceField(queryset= \ question.answers_set) Now in this example that's actually not too bad. It's still a bit hacky as we tap into the fields dict after calling the parents constructor. I have a variant of this where I moved the … -
Nicer dynamic forms in django
I used to make dynamic forms for Django in very bad way, I'm happy to admit that now as I've improved my process. Basically the solution is to use type() as I'm sure many of you know. If your doing that already there isn't much for you here. If your messing around with 'self.fields["name"]' in your forms then read on. Lets take a simple use case; a quiz system. You can think of it like who wants to be a millionaire. We will have a Question with four possible answers. So two models... from django.db import models class Question(models.Model): test = models.CharField(max_length=128) class Answer(models.Model): question = models.ForeignKey(Question) test = models.CharField(max_length=20) is_correct = models.BooleanField(default=False) Basically we want a form that stores both the question and the answers and checks the answer is a valid choice. You could do it this way. from django import forms class QuizForm(forms.Form): def __init__(self,question, *args, **kwargs): super(QuizForm, self).__init__(*args, **kwargs) self.fields['question'] = forms.IntegerField(widget= \ forms.HiddenInput, initial=question.id) self.fields['answers'] = forms.ModelChoiceField(queryset= \ question.answers_set) Now in this example that's actually not too bad. It's still a bit hacky as we tap into the fields dict after calling the parents constructor. I have a variant of this where I moved the … -
Paginated feed for cmsplugin_feed
In my previous post [1] I wrote about my experience of writing a new plugins for django-cms [2]. This plugin gives you the capability to add a feed to a django-cms' Page.I ended my post by asking about the best practice used to paginate the content of a plugin. Since I didn't get flooded by the answers I assumed that this shouldn't be different than doing it on a django app. Here it is what the fine django documentation says about this topic.So I have decided to implement this approach, the key point here is to understand that django-cms' plugin has access to the context :class FeedPlugin(CMSPluginBase): [...] def render(self, context, instance, placeholder): feed = get_cached_feed(instance) if instance.paginate_by: is_paginated =True request = context['request'] [...]This capability lets your plugin react to the GET and POST parameters. Once I have understood this the only thing that I had to do is to use the django's Paginator on the list of feed entries. As you can see in the code below there is nothing specific to django-cms there. is_paginated =True request = context['request'] feed_page_param = "feed_%s_page" %str(instance.id) feed_paginator = Paginator(feed["entries"], instance.paginate_by) # Make sure page request is an int. If not, deliver first … -
Django, it's just Python.
'It's just python' A statement I've heard a number of Django people use. I happen to think its quite relevant and important to remember. Django is stupidly easy to get started with, you feel empowered when you make your first website and its amazing. You can do so much and you only need to write a few lines of code. At this point yes you are writing python, but, really your not. I'm talking Django tutorial level code, after completing that you wouldn't claim to being a python coder would you? Luckily after playing with Django for a bit I realised how great python is as a language and I chose to do my MSc Dissertation research with python - that was a great idea. It was my first real piece of python code without Django1 and I really struggled at first, it was only at this point that I ran into strange gotchas and silly things like circular imports that at the time confused me. Django really encourages a set layout and manages hooking it all together for you. I learned a lot in this project about python, it's by far the most profitable piece of work at university … -
Running django with daemontools
Running django with daemontools -
feed extension for django-cms
I have been lately looking at the open source CMS alternatives based on django. After some times investigating I have decided to give django-cms [1] a try.django-cms provides an API to write plugin it is well documented [2] and you can also look the implementation of plugins listed there [3]. I have decided to experiment with it by writing a plugin that displays the content of a feed into a page. The source code is available on my bitbucket account in a project called cmsplugin-feed. The development of this plugin has been relatively straight forward and once you get to know the conventions defined to implement an extension. You feel like you are writing python code for a django application. The CMS part does not stand on your way at least it didn't in my experimentation.Here it is 2 screenshots showing this plugin in action :In order to add a feed you need give a name and an URL to your feedThen the plugin displays the field on a page.I would be interested to read from someone the "best practice" to paginate the content of a plugin. Ideally I would like to add a parameter for every feed indicating how many items I … -
Using bpython shell with django (and some Ipython features you should know)
What is bpython? bpython is a fancy interface to the Python interpreter for Unix-like operating system. says the bpython home page. It provides syntax highlighting, auto completion, auto-indentation and such stuff. Unlike iPython, which implements then entire shell functions and emulates the standard python shell, and adds enhancements, bpython just adds features on top of [...] Related posts:Better Python package management using source and version control systems Tools of Pro Django developer – aka What powers dinette and almost every app we write. -
Using DHTMLXgrid in a Django application
DHTMLX grid is a complete grid solution for browsing and editing grid like, spreadsheet like data from various sources. This tutorial will show you how to connect server-side Django views with client-side xgrid features. -
Fixing PostgreSQL's default encoding on Ubuntu 9.10
Ubuntu 9.10 installs PostgreSQL with a default encoding of SQL_ASCII. This is dumb: SQL_ASCII basically means “I don’t care about the encoding of my data; just store garbage.” This is especially annoying since PostgreSQL will actually prevent you from creating new databases with a different encoding: if you try, you’ll be told that the “new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII).” My fix was to just blow away the default cluster and re-create it with a UTF8 encoding. -
YTM launch!!
No more beta for YouTellMe.nl The website which is taking over the Dutch product comparison market is officially going out of beta @ 8 o clock. Party in Amsterdam, Keizersgracht 182 :) Festivities starting right now! Things are going well, looking very forward to international launch. We’ve changed a lot since the first reviews! Beter pictures coming after the event [...] -
Using the jQuery Autocomplete Plugin with Django
Here’s another look into the development of ComicBinder. There’s already a good tutorial on how to use an autocomplete plugin with Django, but I wanted to use this much snazzier plugin. The Process Load both jquery.autocomplete.min.js and jquery.autocomplete.css in your page. In your form object, create a CharField to hold your autocomplete. Something like: title [...] -
Django Object Permissions Proof of Concept
In the process of refactoring an app, we realized that we needed a general purpose, object-level (or row-level) permission system. So we looked around and found two: django-authority and django-granular-permissions. Django Granular permissions was closest to what we wanted, but not as complete as Django Authority. We figured we could flush out Granular Permissions and all would be well. So one thing lead to another and it has morphed into something different. Because of the complexity of object-level or row-level permissions, we wanted to get feedback on the current proof-of-concept from the Web’s best and brightest: the Django developer community. First the code: on github.com For discussions, I created a public Google Wave, as it seems more appropriate than just comments on this blog or via e-mail list. Since I don’t know how to reference them any other way, search for django permission with:public. If some of you aren’t on Google Wave yet and want to comment, I do have some invites. Now my introduction to the code: There is documentation, although it is preliminary. There is a script build_docs.sh that will build it and put it into docs/_build/html if you have Sphinx installed. It walks you through assigning permissions on your own code, …