diff --git a/api/serializers.py b/api/serializers.py index 7abbb74..3ff3623 100755 --- a/api/serializers.py +++ b/api/serializers.py @@ -113,7 +113,9 @@ class InstitutionSerializer(serializers.HyperlinkedModelSerializer): class TransactionSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Transaction - fields = ['url', 'datetime', 'Bank', 'details'] + fields = ['url', 'authorized_date', + 'bank', 'name','details','slice','trans_id', + 'updated_at','created_at'] class SliceSerializer(serializers.HyperlinkedModelSerializer): 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/migrations/0008_auto_20210211_0136.py b/qrtr_account/migrations/0008_auto_20210211_0136.py new file mode 100644 index 0000000..6842203 --- /dev/null +++ b/qrtr_account/migrations/0008_auto_20210211_0136.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.3 on 2021-02-11 01:36 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('qrtr_account', '0007_auto_20210128_0325'), + ] + + operations = [ + migrations.RenameField( + model_name='transaction', + old_name='Slice', + new_name='slice', + ), + ] diff --git a/qrtr_account/migrations/0009_auto_20210211_0202.py b/qrtr_account/migrations/0009_auto_20210211_0202.py new file mode 100644 index 0000000..74074bb --- /dev/null +++ b/qrtr_account/migrations/0009_auto_20210211_0202.py @@ -0,0 +1,20 @@ +# Generated by Django 3.1.3 on 2021-02-11 02:02 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ('qrtr_account', '0008_auto_20210211_0136'), + ] + + operations = [ + migrations.AlterField( + model_name='slice', + name='parent_type', + field=models.ForeignKey(limit_choices_to=models.Q(models.Q(('app_label', 'qrtr_account'), ('model', 'bank')), models.Q(('app_label', 'qrtr_account'), ('model', 'slice')), _connector='OR'), null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype'), + ), + ] diff --git a/qrtr_account/migrations/0010_auto_20210211_0202.py b/qrtr_account/migrations/0010_auto_20210211_0202.py new file mode 100644 index 0000000..ae70c39 --- /dev/null +++ b/qrtr_account/migrations/0010_auto_20210211_0202.py @@ -0,0 +1,20 @@ +# Generated by Django 3.1.3 on 2021-02-11 02:02 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ('qrtr_account', '0009_auto_20210211_0202'), + ] + + operations = [ + migrations.AlterField( + model_name='slice', + name='parent_type', + field=models.ForeignKey(blank=True, limit_choices_to=models.Q(models.Q(('app_label', 'qrtr_account'), ('model', 'bank')), models.Q(('app_label', 'qrtr_account'), ('model', 'slice')), _connector='OR'), null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype'), + ), + ] diff --git a/qrtr_account/migrations/0011_auto_20210211_0203.py b/qrtr_account/migrations/0011_auto_20210211_0203.py new file mode 100644 index 0000000..469c9e9 --- /dev/null +++ b/qrtr_account/migrations/0011_auto_20210211_0203.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.3 on 2021-02-11 02:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('qrtr_account', '0010_auto_20210211_0202'), + ] + + operations = [ + migrations.AlterField( + model_name='slice', + name='parent_id', + field=models.PositiveIntegerField(null=True), + ), + ] diff --git a/qrtr_account/migrations/0012_slice_description.py b/qrtr_account/migrations/0012_slice_description.py new file mode 100644 index 0000000..c2ec032 --- /dev/null +++ b/qrtr_account/migrations/0012_slice_description.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.3 on 2021-02-11 02:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('qrtr_account', '0011_auto_20210211_0203'), + ] + + operations = [ + migrations.AddField( + model_name='slice', + name='description', + field=models.TextField(blank=True, max_length=255, null=True), + ), + ] diff --git a/qrtr_account/models.py b/qrtr_account/models.py index f625ca0..01fe781 100644 --- a/qrtr_account/models.py +++ b/qrtr_account/models.py @@ -60,6 +60,7 @@ class Slice(models.Model): name = models.CharField(max_length=250) icon = models.CharField(max_length=250) budget = models.DecimalField(decimal_places=3, max_digits=100) + description = models.TextField(max_length=255, null=True, blank=True) avail_parents = models.Q( app_label='qrtr_account', model='bank') | models.Q( @@ -68,8 +69,8 @@ class Slice(models.Model): parent_type = models.ForeignKey( ContentType, limit_choices_to=avail_parents, - on_delete=models.CASCADE) - parent_id = models.PositiveIntegerField() + on_delete=models.CASCADE, null=True, blank=True) + parent_id = models.PositiveIntegerField(null=True) is_unsliced = models.BooleanField(default=False) slice_of = GenericForeignKey('parent_type', 'parent_id') @@ -117,7 +118,7 @@ class Transaction(models.Model): related_name='transactions') name = models.CharField(max_length=255) details = models.JSONField() - Slice = models.ForeignKey(Slice, on_delete=models.SET_NULL, null=True) + slice = models.ForeignKey(Slice, on_delete=models.SET_NULL, null=True) trans_id = models.CharField(max_length=255) updated_at = models.DateTimeField(auto_now=True) created_at = models.DateTimeField(auto_now_add=True) diff --git a/qrtr_account/views.py b/qrtr_account/views.py index c6f6322..fce799e 100644 --- a/qrtr_account/views.py +++ b/qrtr_account/views.py @@ -1,6 +1,7 @@ from django.shortcuts import render from rest_framework import viewsets, mixins from .models import Account, Bank, Institution, Transaction, Slice, Rule +from rest_framework.permissions import IsAuthenticated from connection.models import Connection, ConnectionType from api.serializers import (AccountReadSerializer, AccountWriteSerializer, BankSerializer, BankSerializerPOST, @@ -46,6 +47,13 @@ class BankViewSet(viewsets.ModelViewSet): return BankSerializer +class SliceViewSet(viewsets.ModelViewSet): + """API endpoint that allows Banks to be viewed. + """ + queryset = Slice.objects.all() + serializer_class = SliceSerializer + + class InstitutionViewSet(viewsets.ReadOnlyModelViewSet): """API endpoint that allows Banks to be viewed. """ @@ -53,18 +61,18 @@ class InstitutionViewSet(viewsets.ReadOnlyModelViewSet): serializer_class = InstitutionSerializer -class TransactionViewSet(viewsets.ReadOnlyModelViewSet): +class TransactionViewSet(viewsets.ModelViewSet): """API endpoint that allows Banks to be viewed. """ queryset = Transaction.objects.all() serializer_class = TransactionSerializer - -class SliceViewSet(viewsets.ReadOnlyModelViewSet): - """API endpoint that allows Banks to be viewed. - """ - queryset = Slice.objects.all() - serializer_class = SliceSerializer + 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):