Is there a way to autoincrement a field with respect to the previous one…e.g if the previous record has the value 09-0001, then the next record should be assigned 09-0002 and so one…ideas? I’m thinking of overriding the save method, but how exactly I’m not so sure
Share
Django won’t let you have more than one AutoField in a model, and you already have one for your primary key. So you’ll have to override save and will probably need to look back at the table to figure out what to increment.
Something like this:
Note that without some kind of locking in your save method, you can run into a concurrency problem (two threads trying to store the same values in code and number).