This template filter converts the filtered variable to json. I added comment to that snippet to:
1. Pass a kwarg cls=ModelJSONEncoder to simplejson.dumps to get handling of django.db.models.Model objects (get ModelJSONEncoder here). And as sk1p pointed out, you’ll also get handling of datetime objects and decimals for free.
2. Put jsonify.is_safe=True after register.filter so you don’t need to do {% autoescape off %} or |safe every time you use jsonify.