I am working on a system that lists out a range of products sorted by their product code. The product codes are made up of two letters for the followed by a number, for example EG1.
I currently sort these products by doing a simple
Product.objects.order_by('product_code')
,
however as there can be multiple digit product codes (for example EG12), these will come out above ahead of the single digit codes. i.e EG1, EG11, EG12, EG13 ... EG19, EG2, EG20 etc
I know that adding leading zeros to the product codes will fix this (i.e EG01 rather than EG1) but as there is already printed literature and an existing site using EG1 this is not an option.
Is there a way to fix this to show these products in the correct order?