python - Django autoincrement IntergerField by rule -


i have special case, customer requires specific (legacy) format of booking numbers, first 1 starts current year: 2015-12345 every year have start 0

the other 1 starting foreign-key: 7-123 first document created every user gets number 1, , on.

unfortunately there long lists starting booking number, fetching records , calculating booking number not option. have thought overriding save() method, reading , auto-incrementing manually, simultaneous inserts?

the best , reliable way sql trigger eliminate worries simultaneous inserts. overriding save method workable.

explicitly declare primary key field , choose integer it. in save method if primary key none means saving new record, query database determine should new primary key, asign , save. wherever call save method need have atomic transaction , retry save if fails.

btw, starting 0 each year. that's going leading conflicts. have prefix primary key year , strip out @ time display it. (believe me don't want mess composite primary keys in django)


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -