Posted By

viroide on 06/07/13


django mongodb sleepymogoose templatetag

Versions (?)

How to read "_id" field of an object in django templates

 / Published in: Django

It's imposible to read de "id" field en django templates ( {{}} === error) So, to read it, you must do a templatetag.

Now you hace the templatetag, you can use it like this: {{element|pk}}

  1. @register.filter(name='pk')
  2. def pk(value):
  3. if type(value) == type({}):
  4. if value.has_key('_id'):
  5. value = value['_id']
  6. return unicode(value)

Report this snippet  

You need to login to post a comment.