Django custom fields: descriptor class gotcha

Let’s say you are making a custom field type that uses different attname and name properties, like ForeignKey fields do.

Probably this is so that you can store the raw value in the db under field.attname, while transparently accessing a converted value via

Probably to make that mechanism work you are needing a descriptor class, much like a ForeignKey field has a ReverseSingleRelatedObjectDescriptor which handles the get/set functionality for the field – allowing you to get or set model instances, while a plain id is saved in the db under field.attname.

Since there’s no specific docs on how to do this you probably started by copying Django’s example, like the ForeignKey mechanism above. Read more of this post

Doing my bit to Promote JS

JavaScript JS Documentation: JS Array slice, JavaScript Array slice, JS Array .slice, JavaScript Array .slice
This is a great campaign to bump up the Google rank of proper Javascript docs, to get them up above the noise, making them easier to find. I’m doing my bit by posting this here, if you want to help then get your own code and join in.

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:

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 🙂