Custom Unique Registration Number Required

42 views
Skip to first unread message

chen...@gmail.com

unread,
Apr 5, 2023, 9:42:30 PM4/5/23
to Django users
Good day all

I am new to django and I need assistance where I can make a unique registration number via model with the following format

ch2023ed0213 where 

'ch' stands for abbreviated school name,
'2023' year of programme,
'ed' for department and 
'0213' student unique number..

Urls Link or recorded tutorials are welcome.

Thank you

Amine Khetim

unread,
Apr 6, 2023, 9:17:26 AM4/6/23
to Django users
Hi,

You can add a validator to your field with a custom alogithm to verify that the format is correct : Validators | Django documentation | Django (djangoproject.com)

Don't hesitate if you need more information

Martin Mwai

unread,
Apr 11, 2023, 8:44:53 AM4/11/23
to Django users
It depends whether you want it on the front end or backend :
for front end have a function thats add the above abbreviations before inserting the data into the form. assuming the form has all the variables (school, year, dept, 0213) parse this to the function then it returns registration number . 

if its in the admin section you may create a function within the model class and  use super to return registration number before saving. 
Reply all
Reply to author
Forward
0 new messages