Skip to content

Add sort field to evalutor result filterset - #46

Merged
willbarton merged 3 commits into
mainfrom
api-sorting
Mar 30, 2026
Merged

Add sort field to evalutor result filterset#46
willbarton merged 3 commits into
mainfrom
api-sorting

Conversation

@willbarton

@willbarton willbarton commented Mar 23, 2026

Copy link
Copy Markdown
Member

This adds a sort field to the evaluator results filterset. From the evaluator results endpoint in the API this should enable sorting, either ascending (with just the sort field) or descending (prefixing the sort field with -), on any of the listed fields (which are those available from AccountActivity).

This leverages the existing django-filters filter set by adding an [OrderingFilter field](https://django-filter.readthedocs.io/en/stable/ref/filters.html#django_filters.filters.OrderingFilter

For example, the query arguments ?view=all&sort=-activity_date would sort by activity descending.

To sort on multiple fields, they can be separated by comma, for example: ?view=all&sort=-activity_date,current_bal will sort by activity date descending (newest first) and by current balance ascending (lowest first).

Once merged, I will add the following to the API wiki page's section on the evaluator results view:


If the sort parameter is given the results will be sorted by the given field(s) either ascending (using the field name without decoration) or descending (prefixing the field name with -). Multiple fields can be sorted by comma-separating them. Fields the results can be sorted on are:

  • activity_date
  • cons_acct_num
  • port_type
  • acct_type
  • date_open
  • credit_limit
  • hcola
  • id_num
  • terms_dur
  • terms_freq
  • smpa
  • actual_pmt_amt
  • acct_stat
  • pmt_rating
  • php
  • php1
  • spc_com_cd
  • compl_cond_cd
  • current_bal
  • amt_past_due
  • orig_chg_off_amt
  • doai
  • dofd
  • date_closed
  • dolp
  • int_type_ind
  • account_holder__cons_info_ind
  • account_holder__ecoa
  • account_holder__cons_info_ind_assoc
  • account_holder__ecoa_assoc
  • k2__purch_sold_ind
  • k2__purch_sold_name
  • k4__balloon_pmt_amt
  • l1__change_ind
  • l1__new_id_num
  • l1__new_acc_num

For example, ?view=all&sort=-activity_date,current_bal will sort by activity date descending (newest first) and by current balance ascending (lowest first).


Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Passes all existing automated tests

Comment thread django/evaluate_m2/filters.py Outdated

@virginiacc virginiacc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@willbarton This looks great! 🎉

Looking at the list of fields, I realized I forgot about the consumer account number column in the evaluator results table when we were discussing which fields should be sortable. Would it be possible to make that one sortable too?

willbarton and others added 3 commits March 30, 2026 08:20
This adds a `sort` field to the evaluator results filterset. For the evaluator results endpoint in the API you should be able to sort, ascending (with just the sort field) or descending (prefixing the sort field with `-`), any of the listed fields (which are those available from `AccountActivity`).

For example, the query arguments `?view=all&sort=-activity_date` would sort by activity date descending.

To sort on multiple fields, they can be separated by comma, for example: `?view=all&sort=-activity_date,current_bal` will sort by activity date descending (newest first) and by current balance ascending (lowest first).
Co-authored-by: Betsy Lorton <schbetsy@users.noreply.github.com>
@willbarton

Copy link
Copy Markdown
Member Author

@virginiacc added cons_acct_num to sortable fields!

@virginiacc virginiacc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works perfectly -- thanks, @willbarton!

@willbarton
willbarton merged commit e0a0f61 into main Mar 30, 2026
3 checks passed
@willbarton
willbarton deleted the api-sorting branch March 30, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants