Django: How to write query to sort using multiple columns, display via template

There are several levels for display ordered models objects in template, each one overwrite the previous level:

  1. (MODEL LEVEL) Meta attribute ordering as shows @Bithin in his answer (more on django docs)
  2. (VIEW LEVEL) QuerySet order_by method as you have tried in your view example, which would works
    as you want if add other fields to sort:

    Customer.objects.order_by('state', 'city_name', 'customer_name')

    (more on django docs). Note that .all() is not needed here.

  3. (TEMPLATE LEVEL) regroup template tag need to use nested in your sample (more on django docs)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)