Commit f49c3927 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Add support for ordering in ListCommand

Make list command order results either by 'order_by' class attribute,
or by primary key.
parent e3cb877a
...@@ -104,6 +104,8 @@ class ListCommand(BaseCommand): ...@@ -104,6 +104,8 @@ class ListCommand(BaseCommand):
# Default filters and excludes # Default filters and excludes
filters = {} filters = {}
excludes = {} excludes = {}
# Order results
order_by = None
# Fields used only with user_user_field # Fields used only with user_user_field
astakos_url = None astakos_url = None
...@@ -240,6 +242,9 @@ class ListCommand(BaseCommand): ...@@ -240,6 +242,9 @@ class ListCommand(BaseCommand):
except Exception as e: except Exception as e:
raise CommandError("Can not filter results: %s" % e) raise CommandError("Can not filter results: %s" % e)
order_key = self.order_by if self.order_by is not None else 'pk'
objects = objects.order_by(order_key)
# --display-mails option # --display-mails option
display_mails = options.get("display_mails") display_mails = options.get("display_mails")
if display_mails: if display_mails:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment