Login

Snippets by kumbry

Snippet List

self-related objects list with links

The problem was to output self-related objects (like category objects which may be a sub-category in any category and so on) in unordered list with links to certain view (providing some object.id arg). Its somewhat like unordered_list tag but takes plain list of objects and provides links. For example: category_list = Category.objects.all() In your template: {% related_linked_list category_list view_category %} This tag, however, have some limits: 1. Model shoud have self-related "parent" and id that may be passed into view. 2. In model parent = ForeignKey('self', ...) *related_name* is "child_set". But its simple enough that you may easily rewrite it for your own needs. :)

  • template-tags
  • output
Read More

kumbry has posted 1 snippet.