Archives

Categories

Designed to hold a list of pages and page ranges for a book/magazine index.

A custom model field (and accompanying form field) that saves comma-separated pages and page ranges in human-readable string form. Includes some clean-up code, so that you can add a new page or range at the end of an existing entry, and it will put it in numeric order and combine runs into ranges. So this:

becomes the tidy

NOTE: If you comment out the raising of the ValidationError in the form field’s validate() method, it will actually clean up any extraneous characters for you (which could be dangerous, but for me is usually what I want), so even this horrible mess:

gets cleaned to

*This is the first custom field I’ve ever written for Django, so may be a little rough but seems to work fine.

If you have comments, please share them with me on Twitter or Facebook.

You should check out my podcast about movie magic and VFX: The Optical.