Hi kenkennie!
I think the problem lies in the algorithm, not the technology platform, language or framework.
You can use .zfill(n) to add n-1 zeros in front of the string. Then add INV in front
eg:
# get last item
item = Invoice.objects.filter(invoice_number__istartswith='INV').order_by('-create_date')[0]
# last index
index = int(item['invoice_number'][-3:]) # = int('003') = 3
res = 'INV-' + str(x+1).zfill(3)
# res = 'INV-004'
Sorry to ask. This should be in models.py or views.py? if you could write the function i would really appreciate
i am new to django building my first project
first of all define the prefix which you want to use for your unique numbers, then determine the starting for your unique numbers and it could be integers value you choose such as 1. Import the intertools module which provides convenient toolls for interator-base programing. That’s It.
@harrychris946 - Unfortunately, the itertools module is not going to help ensure uniqueness across multiple processes using a database in the Django environment. The situation is a bit more complex than if it were just a function running in a single Python program.