I have to sort a list of objects containing hostnames.
The hostnames are in these formats: h1, h5, h10, h12, h12-abc, h1000, x10
If i use order_by('hostname') it will order like this:
h1, h10, h1000, h12, h12-abc, h5, x10
How would i achieve an ordering like this:
h1, h5, h10, h12, h12-abc, h1000, x10
The hostnames always begin with a char, then 1-4 digits and partly an extension, like for example '-abc'.
I guess i have to use Substr() to extract the number and order the numbers somehow, that '10' will not be listed before '5'.
With a search i found some old examples with extra() but the Django documentation says it will be deprecated in future and 'Use this method as a last resort' https://docs.djangoproject.com/en/2.1/ref/models/querysets/#extra
What is a future-proof way to do it?