I have a simple model similar to the model below:
class ServiceIncoice(MyCustomRegistrationModel):
(...)
number = models.CharField(max_length=60)
(...)
The field number contains integer values generally. The user might want to use only numbers or alphanumerical codes.
The problem is I need to get the last value of the field number when the user wants to create a new ServiceInvoice instance and then add 1 to the last value. For example:
- Id = 1, Number = 13
- Id = 2, Number = 2
- Id = 3, Number = 16
The next item should have Id = 4 and Number = 17. However when I execute
ServiceInvoice.objects.all().latest('number')
It returns 2 which isn't what I want. I have tried this solution, this one and this one. Anyone of them worked for me because I need the highest number of any given ServiceInvoice.
Thanks in advance.