Django: chaining custom model Manager methods

As Simon Willison points out:

“Django supports adding custom methods for accessing the ORM through the ability to implement a custom Manager… The downside of this approach is that methods added to a manager can only be used at the beginning of the chain.”

My modest contribution is in this comment on DjangoSnippets…

Snippet: ‘exclusive boolean’ field for Django models

“Sometimes you want to be able to make one (and only one) row in your model ‘featured’ or ‘the default one’.”

I think the snippet is fairly self explanatory:

More django-mptt goodness: FilteredSelectMultiple m2m widget

If you are using django-mptt to manage content (eg heirarchical categories) then it needs a bit of help to make a nice admin interface. For many-to-many fields, Django provides the quite nice FilteredSelectMultiple widget (a two-pane selection list with search box) but it only renders ‘flat’ lists… if you have a big category tree it’s going to be confusing to know what belongs to what. Also, list items are sorted alphabetically by the js, which won’t be what you want.

In this post I’ll be extending FilteredSelectMultiple to show the tree structure in the list:

Read more of this post

Making admin bulk delete action work with django-mptt

For the past month and a half I have been learning Django (and therefore Python…) at my new job.

I’m very impressed how quick it has been to learn, and particularly with how complete and well thought-through the Django framework is. Python is nice too, I’m not missing all the $ signs, semi-colons and curly braces at all :)

For the project I’ve been working on we used django-mptt to manage a ‘Modified Pre-Order Tree Traversal‘ scheme for a heirarchical Category model.

django-mptt works great but to properly manage an mptt model in the django admin you have to do a bit of hacking:
Read more of this post

free jQuery plugin: ‘dataPanel’ flexible tooltip

I was looking around recently for a jQuery tooltip plugin. I wanted a bit more flexibility in styling the content of the tooltip than the ones I found though… basically I wanted more than just ‘title’ and ‘description’.

More of an informational panel than a little tooltip, hence ‘dataPanel’.

In the one I made you can have an arbitrary number of fields within the tooltip div – you just pass the plugin a css selector for each one when you attach it to your source element.

Read more of this post

Javascript: ISO8601 parser and pretty dates

Compared to PHP, with its many helpful date functions, working with dates in Javascript is a pain in the neck.

The js Date object can parse some human-readable strings into a date, but with the rise of RSS etc (in my case it was working with Google gdata apis…) you’ll often be encountering ISO8601 date strings.  Apparently ECMAScript 5 will include built in methods to parse this standard format, but until that’s available it’s a bit of a headache.

Read more of this post

Cellular music

Haven’t even listened to it yet, but found this today:

Looks pretty neat :)


Get every new post delivered to your Inbox.