0

I have a queryset to be ordered alphabetically. I have this series of names such as: Mission 1, Mission 2 etc. My problem is that, once the database has more than 9 entries, the sorting works like that: Mission 1, Mission 11, Mission 2, Mission 3 etc. I tried a query like:

Mission.objects.all().order_by('name')

My Mission model is:

class Mission(models.Model):
name = models.CharField(max_length=200)
duration_dual = models.DurationField(blank=True, null=True)
duration_solo = models.DurationField(blank=True, null=True)
training_course = models.ForeignKey(
    TrainingCourse, on_delete=models.CASCADE)
note = models.TextField(null=True, blank=True)
solo_flight = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

def __str__(self):
    return self.training_course.name + ' ' + self.name

but the problem is still there. I need to have an order like --> Mission 1, Mission 2 .... Mission 9, Mission 10, Mission 11 etc.

Giorgio Scarso
  • 386
  • 1
  • 2
  • 11

0 Answers0