djaodjin / djaodjin-saas

Django application for software-as-service and subscription businesses
Other
564 stars 124 forks source link

Supports sort by multiple columns #182

Closed smirolo closed 5 years ago

smirolo commented 5 years ago

This requires to replaces extra_views by filters (see saas/api/accounts.py for example).

The only thing to do (I believe) is to replace sort_fields_aliases by ordering_fields, add SearchFilter and OrderFilter in filter_backends and remove the extra_mixins from the inherited classes.

knivets commented 5 years ago

What about aliased that hide the relation fields? Like ('slug', 'user__username'). That would require to either change the Vue code to pass the updated arguments or building an alias solution. Btw there is a popular library that we might leverage here. It implements aliasing and a bunch of other things -- https://django-filter.readthedocs.io/en/master/ref/filters.html#orderingfilter.

smirolo commented 5 years ago

Yes. use django-filter for aliases if those are included.

smirolo commented 5 years ago

PR #200 fails on Django>=2.1

File "TOXENV/py36-django2.1/djaodjin-saas/reps/djaodjin-saas/saas/filters.py", line 156, in get_valid_fields
rel = queryset.model._meta.get_field(relation).rel
AttributeError: 'ForeignKey' object has no attribute 'rel'
knivets commented 5 years ago

We need to use remote_field instead of rel For Django 2.0+

smirolo commented 5 years ago

OK. Add a get_related_field method in compat.py that handles both Django1.11 and Django2.0+. Thank you.

smirolo commented 5 years ago

tested. tests pass on both Django1.11 and Django2.2