| @@ -1,3 +1,5 @@ | |||||
| from django.contrib import admin | from django.contrib import admin | ||||
| from .models import * | |||||
| # Register your models here. | |||||
| admin.site.register([Invoice, Item]) | |||||
| @@ -25,4 +25,4 @@ class Item(models.Model): | |||||
| return self.amount * self.quantity | return self.amount * self.quantity | ||||
| def __str__(self): | def __str__(self): | ||||
| return self.name | |||||
| return self.id | |||||
| @@ -0,0 +1,14 @@ | |||||
| from rest_framework import serializers | |||||
| from .models import Item, Invoice | |||||
| class ItemSerializer(serializers.ModelSerializer): | |||||
| class Meta: | |||||
| model = Item | |||||
| fields = ['id', 'name', 'amount', 'quantity', 'invoice', 'item_total'] | |||||
| class InvoiceSerializer(serializers.ModelSerializer): | |||||
| class Meta: | |||||
| model = Invoice | |||||
| fields = ['id', 'project', 'invoice_id', 'raised_date', 'due_date', 'paid_date', 'is_archived'] | |||||
| @@ -0,0 +1,7 @@ | |||||
| from django.urls import path | |||||
| from . import views | |||||
| urlpatterns = [ | |||||
| path('invoices/', views.InvoiceList.as_view()), | |||||
| path('invoice-items/', views.ItemList.as_view()), | |||||
| ] | |||||
| @@ -1,3 +1,26 @@ | |||||
| from django.shortcuts import render | |||||
| from rest_framework.response import Response | |||||
| from rest_framework.views import APIView | |||||
| from rest_framework.authentication import TokenAuthentication, SessionAuthentication | |||||
| from rest_framework.permissions import IsAuthenticated | |||||
| from .models import Item, Invoice | |||||
| from .serializers import ItemSerializer, InvoiceSerializer | |||||
| # Create your views here. | |||||
| class ItemList(APIView): | |||||
| authentication_classes = [TokenAuthentication, SessionAuthentication] | |||||
| permission_classes = [IsAuthenticated] | |||||
| def get(self, request): | |||||
| items = Item.objects.filter(pk=Item.invoice) | |||||
| serializer = ItemSerializer(items, many=True) | |||||
| return Response(serializer.data) | |||||
| class InvoiceList(APIView): | |||||
| authentication_classes = [TokenAuthentication, SessionAuthentication] | |||||
| permission_classes = [IsAuthenticated] | |||||
| def get(self, request): | |||||
| items = Invoice.objects.all() | |||||
| serializer = InvoiceSerializer(items, many=True) | |||||
| return Response(serializer.data) | |||||
| @@ -7,6 +7,7 @@ from client import urls as clientUrls | |||||
| from employee import urls as employeeUrls | from employee import urls as employeeUrls | ||||
| from project import urls as projectUrls | from project import urls as projectUrls | ||||
| from representative import urls as representativeUrls | from representative import urls as representativeUrls | ||||
| from invoice import urls as invoiceUrls | |||||
| schema_view = get_schema_view( | schema_view = get_schema_view( | ||||
| @@ -33,7 +34,8 @@ urlpatterns = [ | |||||
| path('', include(clientUrls)), | path('', include(clientUrls)), | ||||
| path('', include(employeeUrls)), | path('', include(employeeUrls)), | ||||
| path('', include(projectUrls)), | path('', include(projectUrls)), | ||||
| path('', include(representativeUrls)) | |||||
| path('', include(representativeUrls)), | |||||
| path('', include(invoiceUrls)) | |||||
| ])) | ])) | ||||
| ])), | ])), | ||||
| ] | ] | ||||