[Answer]-Django Sorting a List inside a model

1👍

You can set the ordering and many other options for a model through the use of the meta class. So for your example:

class Address(models.Model):
    address = models.CharField(max_length=20)
    ...

    class Meta:
        ordering = ['address']

This will order Address models in your queryset after they have been queried from the database. This will have no impact on how the data is underlying stored.

👤Isaac

Leave a comment