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 and MultiRangeFormField

Posted on 2014-06-012015-08-15 by Mark Boszko
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.

I'm building a website, and needed a way to save a list of pages and page ranges from a book or magazine. I wanted to to be a little more strict than just saving it as a string without any cleanup or validation, so I wrote a custom Django model field (and accompanying form field).

It either just validates and cleans so that

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

becomes the tidy

4-33, 43-45, 59-65

...or, if you comment out the raising of the ValidationError in the form field's validate() method, it will actually clean up any junk characters for you, so even this horrible mess:

;4-33, 46a fads i44 ,p45o

gets cleaned to

4-33, 44-46

Enjoy!

Mark Boszko

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

© 2025 Mark Boszko | find Mark elsewhere on the internet