FixedCharField is used similarly to CharField, but takes a length attribute, and will only accept strings with that exact length.
class Student(models.Model):
student_id = FixedCharField(length=8)
It currently only supports mysql, sqlite3, and oracle. The port to postgresql should be straightforward but I'm not sure about it so I haven't added it yet.
This is a copy-paste (plus a couple of adaptations) from my project Chango, found at http://launchpad.net/chango/, so in order to keep up with latest updates it might be a good idea to use code directly from there.
- field
- form-field
- fixed-length