code: def render_table_ordering(context, index, title):
      
  
      # title + plain url (=without o paramater)
      new_context = { 'title' : title, 'plain_url' : context['view'].get_query_string(remove=['o']) }
  
      # ordered url
      new_context['ordered_url'] = new_context['plain_url'] + '&o=' + index
  
      # toggled ordering url (only if needed)
      if 'o' in context['request'].GET and ( context['request'].GET['o'] == index or context['request'].GET['o'] == '-%s' % index):
          new_context['toggled_url'] = new_context['plain_url'] + '&o=' + (index if context['request'].GET['o'].startswith('-') else '-' + index) 
          new_context['order_direction'] = 'ascending' if context['request'].GET['o'].startswith('-') else 'descending'
  
      return new_context
docs: Renders a TABLE LAYOUT ordering using given index and a human-readable title for it.
      Note that a new context is created for the template (containing only very few elements needed
      for displaying).
  
      Usage in template: {% render_table_ordering "model_field__submodel_field" "Human-readable Title" %}