From d00fb4b5a15803c23bd0dd6586a9f88404dfe2a7 Mon Sep 17 00:00:00 2001 From: DJ Gillespie Date: Mon, 17 May 2021 20:13:31 -0600 Subject: [PATCH] [QRTR-110] Added Filtering options, and adjusted for Django 3.2 updates. --- core/settings/__init__.py | 7 ++++++- qrtr_account/apps.py | 2 +- qrtr_account/views.py | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/settings/__init__.py b/core/settings/__init__.py index d473630..49e17de 100644 --- a/core/settings/__init__.py +++ b/core/settings/__init__.py @@ -47,6 +47,7 @@ INSTALLED_APPS = [ 'qrtr_account', 'corsheaders', 'rest_framework_simplejwt.token_blacklist', + 'django_filters', ] EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' @@ -92,6 +93,7 @@ TEMPLATES = [ WSGI_APPLICATION = 'core.wsgi.application' +DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases @@ -102,7 +104,10 @@ REST_FRAMEWORK = { 'rest_framework.authentication.SessionAuthentication', 'rest_framework.authentication.TokenAuthentication', 'dj_rest_auth.jwt_auth.JWTCookieAuthentication' - ] + ], + 'DEFAULT_FILTER_BACKENDS': ( + 'django_filters.rest_framework.DjangoFilterBackend', + ) } REST_USE_JWT = True diff --git a/qrtr_account/apps.py b/qrtr_account/apps.py index 527dfe7..8888794 100644 --- a/qrtr_account/apps.py +++ b/qrtr_account/apps.py @@ -2,4 +2,4 @@ from django.apps import AppConfig class QrtrAccountConfig(AppConfig): - name = 'QRTR Account' + name = 'qrtr_account' diff --git a/qrtr_account/views.py b/qrtr_account/views.py index 0fc68e0..fce799e 100644 --- a/qrtr_account/views.py +++ b/qrtr_account/views.py @@ -67,6 +67,13 @@ class TransactionViewSet(viewsets.ModelViewSet): queryset = Transaction.objects.all() serializer_class = TransactionSerializer + filterset_fields = { + 'authorized_date': ['exact', 'lte', 'gte', 'isnull'], + 'updated_at': ['exact', 'lte', 'gte', 'isnull'], + 'created_at': ['exact', 'lte', 'gte', 'isnull'], + 'trans_id': ['exact', 'lte', 'gte', 'isnull'], + } + class RuleViewSet(viewsets.ReadOnlyModelViewSet): """API endpoint that allows Banks to be viewed.