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.models import Group
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from rest_framework import serializers
|
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 user.models import User
|
||||||
from connection.models import Connection, ConnectionType
|
from connection.models import Connection, ConnectionType
|
||||||
from connection.serializers import ConnectionTypeSerializer, ConnectionSerializer
|
from connection.serializers import ConnectionTypeSerializer, ConnectionSerializer
|
||||||
@ -45,6 +45,12 @@ class GroupSerializer(serializers.HyperlinkedModelSerializer):
|
|||||||
fields = ['pk', 'url', 'name']
|
fields = ['pk', 'url', 'name']
|
||||||
|
|
||||||
|
|
||||||
|
class SubscriptionPlanSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = SubscriptionPlan
|
||||||
|
fields = ['pk', 'name', 'status']
|
||||||
|
|
||||||
|
|
||||||
class BankAccountSerializer(serializers.HyperlinkedModelSerializer):
|
class BankAccountSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = BankAccount
|
model = BankAccount
|
||||||
@ -58,6 +64,10 @@ class BankAccountSerializer(serializers.HyperlinkedModelSerializer):
|
|||||||
'balance',
|
'balance',
|
||||||
'ac_type',
|
'ac_type',
|
||||||
'ac_subtype',
|
'ac_subtype',
|
||||||
|
'connection_type',
|
||||||
|
'institution_name',
|
||||||
|
'plan',
|
||||||
|
'plan_name'
|
||||||
]
|
]
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
'balance': {'read_only': True},
|
'balance': {'read_only': True},
|
||||||
|
|||||||
@ -32,7 +32,7 @@ from qrtr_account.views import (AccountViewSet,
|
|||||||
TransactionViewSet,
|
TransactionViewSet,
|
||||||
SliceViewSet, SliceTransactionViewSet,
|
SliceViewSet, SliceTransactionViewSet,
|
||||||
FacebookLogin,
|
FacebookLogin,
|
||||||
TwitterLogin)
|
TwitterLogin, SubscriptionPlanViewSet)
|
||||||
|
|
||||||
from connection.views import ConnectionViewSet, ConnectionTypeViewSet
|
from connection.views import ConnectionViewSet, ConnectionTypeViewSet
|
||||||
|
|
||||||
@ -65,8 +65,9 @@ router.register(r'transactions', TransactionViewSet)
|
|||||||
router.register(r'slices', SliceViewSet)
|
router.register(r'slices', SliceViewSet)
|
||||||
router.register(r'slices/(?P<slice_pk>\d+)/transactions',
|
router.register(r'slices/(?P<slice_pk>\d+)/transactions',
|
||||||
SliceTransactionViewSet, basename='slices')
|
SliceTransactionViewSet, basename='slices')
|
||||||
#router.register(r'connections',ConnectionViewSet)
|
router.register(r'connections',ConnectionViewSet)
|
||||||
router.register(r'connectiontypes', ConnectionTypeViewSet)
|
router.register(r'connectiontypes', ConnectionTypeViewSet)
|
||||||
|
router.register(r'plans', SubscriptionPlanViewSet)
|
||||||
|
|
||||||
# Wire up our API using automatic URL routing.
|
# Wire up our API using automatic URL routing.
|
||||||
# Additionally, we include login URLs for the browsable API.
|
# Additionally, we include login URLs for the browsable API.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from django.contrib import admin
|
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)
|
@admin.register(Account)
|
||||||
@ -25,3 +25,7 @@ class TransactionAdmin(admin.ModelAdmin):
|
|||||||
@admin.register(Slice)
|
@admin.register(Slice)
|
||||||
class SliceAdmin(admin.ModelAdmin):
|
class SliceAdmin(admin.ModelAdmin):
|
||||||
pass
|
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):
|
def __str__(self):
|
||||||
return f"{self.name}"
|
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):
|
class Institution(models.Model):
|
||||||
@ -39,6 +45,7 @@ class BankAccount(models.Model):
|
|||||||
on_delete=models.CASCADE)
|
on_delete=models.CASCADE)
|
||||||
institution = models.ForeignKey(Institution, on_delete=models.CASCADE,
|
institution = models.ForeignKey(Institution, on_delete=models.CASCADE,
|
||||||
related_name="bank_accounts")
|
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)
|
acc_id = models.CharField(max_length=250, primary_key=True)
|
||||||
nickname = models.CharField(max_length=250)
|
nickname = models.CharField(max_length=250)
|
||||||
official_name = models.CharField(max_length=250,blank=True, null=True)
|
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)
|
ac_subtype = models.CharField(max_length=250, blank=True)
|
||||||
mask = models.CharField(max_length=4,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
|
@property
|
||||||
def qid(self):
|
def qid(self):
|
||||||
return f"B{self.pk}"
|
return f"B{self.pk}"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from rest_framework import viewsets, mixins
|
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.permissions import IsAuthenticated
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from connection.models import Connection, ConnectionType
|
from connection.models import Connection, ConnectionType
|
||||||
@ -11,7 +11,7 @@ from api.serializers import (AccountReadSerializer, AccountWriteSerializer,
|
|||||||
ConnectionSerializer,
|
ConnectionSerializer,
|
||||||
ConnectionTypeSerializer,
|
ConnectionTypeSerializer,
|
||||||
SliceSerializer, SliceTransactionSerializer,
|
SliceSerializer, SliceTransactionSerializer,
|
||||||
RuleSerializer)
|
RuleSerializer, SubscriptionPlanSerializer)
|
||||||
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
|
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
|
||||||
from dj_rest_auth.registration.views import SocialLoginView
|
from dj_rest_auth.registration.views import SocialLoginView
|
||||||
from allauth.socialaccount.providers.twitter.views import TwitterOAuthAdapter
|
from allauth.socialaccount.providers.twitter.views import TwitterOAuthAdapter
|
||||||
@ -62,6 +62,9 @@ class SliceViewSet(viewsets.ModelViewSet):
|
|||||||
# 'slice_of': ['exact']
|
# 'slice_of': ['exact']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SubscriptionPlanViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = SubscriptionPlan.objects.all()
|
||||||
|
serializer_class = SubscriptionPlanSerializer
|
||||||
|
|
||||||
class InstitutionViewSet(viewsets.ReadOnlyModelViewSet):
|
class InstitutionViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
"""API endpoint that allows BankAccounts to be viewed.
|
"""API endpoint that allows BankAccounts to be viewed.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user