Login

Snippets by HM

Snippet List

Paginator Tag for 1.x

This is a [Paginator Tag](http://www.djangosnippets.org/snippets/73/) for 1.x. Since the context is less overfull, the template, paginator.html, needs more logic. Put the tag in your templatetags and the template at the root of a template-directory. The tag will work out of the box in a generic view, other views must provide `is_paginated` set to True, `page_obj`, and `paginator`. You can get the `object_list` from the `page_obj`: `page_obj.object_list`. See [the pagination documentation](http://docs.djangoproject.com/en/1.0/topics/pagination/).

  • tag
  • paginator
Read More
Author: HM
  • 1
  • 4

Reorder fields directly in the ModelForm

Sometimes the order of the fields you get from a model needs to be adjusted when displaying its modelform. If it's just a few fields you can do it in the template, but what if you want to iterate over the form? The fields are stored in a SortedDict, so you can change the order in the __init__ of the form. A bit clunky, yes.

  • newforms
  • modelform
  • field-order
  • workaround
Read More
Author: HM
  • 6
  • 5

HM has posted 2 snippets.