Skip to content
Station in the Metro
Menu
  • Voiceover & Voice Acting
  • CV
  • The Optical Podcast
  • Apps and Scripts
    • Django Internal Links
    • Django MultiRangeField
    • FeedPress Subscribers Status Board Graph Panel
    • Post Atomic Horror Unofficial Episode Guide
    • Markdown Cheat Sheet
    • Proper English Title Caps 2 for iTunes
    • Clean Ripped TV Episodes for iTunes
    • Track Name Clean Parts for iTunes
  • Casio PT-7
    • Photo Galleries
    • Operation Manual
    • Keyboard ribbon cable repair
  • Colophon
Menu

Django MultiRangeField

This post was published more than a few years ago (on 2014-06-01) and may contain inaccurate technical information, outmoded thoughts, or cringe takes. Proceed at your own risk.

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:

4-33, 43, 45, 60-65, 44, 59

becomes the tidy

4-33, 43-45, 59-65

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:

;4-33, 46a fads i44 ,p45o

gets cleaned to

4-33, 44-46

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

Mark Boszko

Film & Video Editor, Voiceover Artist, macOS IT Engineer, and Maker

© 2025 Mark Boszko | find Mark elsewhere on the internet