create subscription plan model and add qol names to api.
This commit is contained in:
parent
8dc43c0132
commit
64e8ae4bab
@ -1,7 +1,7 @@
|
||||
from django.contrib.auth.models import Group
|
||||
from django.contrib.auth import get_user_model
|
||||
from rest_framework import serializers
|
||||
from qrtr_account.models import Account, BankAccount, Institution, Transaction, Slice, Rule
|
||||
from qrtr_account.models import Account, BankAccount, Institution, Transaction, Slice, Rule, SubscriptionPlan
|
||||
from user.models import User
|
||||
from connection.models import Connection, ConnectionType
|
||||
from connection.serializers import ConnectionTypeSerializer, ConnectionSerializer
|
||||
@ -45,6 +45,12 @@ class GroupSerializer(serializers.HyperlinkedModelSerializer):
|
||||
fields = ['pk', 'url', 'name']
|
||||
|
||||
|
||||
class SubscriptionPlanSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = SubscriptionPlan
|
||||
fields = ['pk', 'name', 'status']
|
||||
|
||||
|
||||
class BankAccountSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = BankAccount
|
||||
@ -58,6 +64,10 @@ class BankAccountSerializer(serializers.HyperlinkedModelSerializer):
|
||||
'balance',
|
||||
'ac_type',
|
||||
'ac_subtype',
|
||||
'connection_type',
|
||||
'institution_name',
|
||||
'plan',
|
||||
'plan_name'
|
||||
]
|
||||
extra_kwargs = {
|
||||
'balance': {'read_only': True},
|
||||
|
||||
@ -32,7 +32,7 @@ from qrtr_account.views import (AccountViewSet,
|
||||
TransactionViewSet,
|
||||
SliceViewSet, SliceTransactionViewSet,
|
||||
FacebookLogin,
|
||||
TwitterLogin)
|
||||
TwitterLogin, SubscriptionPlanViewSet)
|
||||
|
||||
from connection.views import ConnectionViewSet, ConnectionTypeViewSet
|
||||
|
||||
@ -65,8 +65,9 @@ router.register(r'transactions', TransactionViewSet)
|
||||
router.register(r'slices', SliceViewSet)
|
||||
router.register(r'slices/(?P<slice_pk>\d+)/transactions',
|
||||
SliceTransactionViewSet, basename='slices')
|
||||
#router.register(r'connections',ConnectionViewSet)
|
||||
router.register(r'connections',ConnectionViewSet)
|
||||
router.register(r'connectiontypes', ConnectionTypeViewSet)
|
||||
router.register(r'plans', SubscriptionPlanViewSet)
|
||||
|
||||
# Wire up our API using automatic URL routing.
|
||||
# Additionally, we include login URLs for the browsable API.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from django.contrib import admin
|
||||
from .models import Account, Institution, BankAccount, Transaction, Slice
|
||||
from .models import Account, Institution, BankAccount, Transaction, Slice, SubscriptionPlan
|
||||
|
||||
|
||||
@admin.register(Account)
|
||||
@ -25,3 +25,7 @@ class TransactionAdmin(admin.ModelAdmin):
|
||||
@admin.register(Slice)
|
||||
class SliceAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
@admin.register(SubscriptionPlan)
|
||||
class SubscriptionPlanAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
27
qrtr_account/migrations/0018_auto_20240118_0319.py
Normal file
27
qrtr_account/migrations/0018_auto_20240118_0319.py
Normal file
@ -0,0 +1,27 @@
|
||||
# Generated by Django 3.2.3 on 2024-01-18 03:19
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('qrtr_account', '0017_alter_slice_balance'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='SubscriptionPlan',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=250)),
|
||||
('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive')], max_length=10)),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='bankaccount',
|
||||
name='plan',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='qrtr_account.subscriptionplan'),
|
||||
),
|
||||
]
|
||||
@ -19,7 +19,13 @@ class Account(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name}"
|
||||
|
||||
|
||||
class SubscriptionPlan(models.Model):
|
||||
name = models.CharField(max_length=250)
|
||||
status = models.CharField(choices=[('active','Active'), ('inactive', 'Inactive')], max_length=10)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name}"
|
||||
|
||||
|
||||
class Institution(models.Model):
|
||||
@ -39,6 +45,7 @@ class BankAccount(models.Model):
|
||||
on_delete=models.CASCADE)
|
||||
institution = models.ForeignKey(Institution, on_delete=models.CASCADE,
|
||||
related_name="bank_accounts")
|
||||
plan = models.ForeignKey(SubscriptionPlan, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
acc_id = models.CharField(max_length=250, primary_key=True)
|
||||
nickname = models.CharField(max_length=250)
|
||||
official_name = models.CharField(max_length=250,blank=True, null=True)
|
||||
@ -48,6 +55,18 @@ class BankAccount(models.Model):
|
||||
ac_subtype = models.CharField(max_length=250, blank=True)
|
||||
mask = models.CharField(max_length=4,blank=True)
|
||||
|
||||
@property
|
||||
def connection_type(self):
|
||||
return self.connection.type.name
|
||||
|
||||
@property
|
||||
def plan_name(self):
|
||||
return self.plan.name
|
||||
|
||||
@property
|
||||
def institution_name(self):
|
||||
return self.institution.name
|
||||
|
||||
@property
|
||||
def qid(self):
|
||||
return f"B{self.pk}"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework import viewsets, mixins
|
||||
from .models import Account, BankAccount, Institution, Transaction, Slice, Rule
|
||||
from .models import Account, BankAccount, Institution, Transaction, Slice, Rule, SubscriptionPlan
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.decorators import action
|
||||
from connection.models import Connection, ConnectionType
|
||||
@ -11,7 +11,7 @@ from api.serializers import (AccountReadSerializer, AccountWriteSerializer,
|
||||
ConnectionSerializer,
|
||||
ConnectionTypeSerializer,
|
||||
SliceSerializer, SliceTransactionSerializer,
|
||||
RuleSerializer)
|
||||
RuleSerializer, SubscriptionPlanSerializer)
|
||||
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
|
||||
from dj_rest_auth.registration.views import SocialLoginView
|
||||
from allauth.socialaccount.providers.twitter.views import TwitterOAuthAdapter
|
||||
@ -62,6 +62,9 @@ class SliceViewSet(viewsets.ModelViewSet):
|
||||
# 'slice_of': ['exact']
|
||||
}
|
||||
|
||||
class SubscriptionPlanViewSet(viewsets.ModelViewSet):
|
||||
queryset = SubscriptionPlan.objects.all()
|
||||
serializer_class = SubscriptionPlanSerializer
|
||||
|
||||
class InstitutionViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
"""API endpoint that allows BankAccounts to be viewed.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user