I have such Django models:
class SavedVariant(models.Model):
family = models.ForeignKey('Family', on_delete=models.CASCADE)
class Family(models.Model):
family_id = models.CharField(db_index=True, max_length=100)
family_id is of such a pattern: CCNNNNNN_CCC_CCCC where C is a character and N is an integer, e.g. SF0637658_WGS_HGSC. I want to order (django order_by?) my SavedVariant models first by preceding chars - CC - then by the number - NNNNNN - and finally by the last chars. Is it possible to do in Django? What would you recommend?
Update
I tried to extract integer from the field, but so far unsuccessful. Here is where I am at:
variant_query = variant_query.annotate(
family_int=Cast(family__family_id__regex=r'\d+', output_field=IntegerField())
).order_by('family_int')
Obviously its just a part of the problem that I am trying to solve. Need to extract an integer part within Cast from family_id and not sure how.