Prechádzať zdrojové kódy

增加支出报表的meun

user 4 rokov pred
rodič
commit
2af2b6bca0

+ 16 - 0
detailmptt/models.py

@@ -26,3 +26,19 @@ class DailyMptt(MPTTModel):
     class MPTTMeta:
         order_insertion_by = ['title']#自然顺序
 
+
+# 权限表
+class Role(models.Model):
+    title = models.CharField(max_length=32)
+    permissions = models.ManyToManyField('Permission')
+
+    def __str__(self):
+        return self.title
+
+#菜单表
+class menu(models.Model):
+    title = models.CharField(max_length=32)
+    url = models.CharField(max_length=32)
+
+    def __str__(self):
+        return self.title

BIN
pivottable/__pycache__/models.cpython-37.pyc


BIN
pivottable/__pycache__/serializer.cpython-37.pyc


BIN
pivottable/__pycache__/views.cpython-37.pyc


+ 37 - 0
pivottable/migrations/0001_initial.py

@@ -0,0 +1,37 @@
+# Generated by Django 3.0.8 on 2020-07-28 11:40
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+import mptt.fields
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Menu',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('name', models.CharField(max_length=100)),
+                ('config', models.TextField()),
+                ('create_at', models.DateTimeField(auto_now_add=True)),
+                ('code', models.CharField(max_length=100)),
+                ('lft', models.PositiveIntegerField(editable=False)),
+                ('rght', models.PositiveIntegerField(editable=False)),
+                ('tree_id', models.PositiveIntegerField(db_index=True, editable=False)),
+                ('level', models.PositiveIntegerField(editable=False)),
+                ('create_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
+                ('parent', mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='pivottable.Menu')),
+            ],
+            options={
+                'abstract': False,
+            },
+        ),
+    ]

+ 16 - 0
pivottable/migrations/0002_delete_menu.py

@@ -0,0 +1,16 @@
+# Generated by Django 3.0.8 on 2020-07-28 11:49
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('pivottable', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.DeleteModel(
+            name='Menu',
+        ),
+    ]

+ 38 - 0
pivottable/migrations/0003_menu.py

@@ -0,0 +1,38 @@
+# Generated by Django 3.0.8 on 2020-07-28 11:55
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+import mptt.fields
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+        ('pivottable', '0002_delete_menu'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Menu',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('name', models.CharField(max_length=100)),
+                ('config', models.TextField()),
+                ('create_at', models.DateTimeField(auto_now_add=True)),
+                ('code', models.CharField(max_length=100)),
+                ('lft', models.PositiveIntegerField(editable=False)),
+                ('rght', models.PositiveIntegerField(editable=False)),
+                ('tree_id', models.PositiveIntegerField(db_index=True, editable=False)),
+                ('level', models.PositiveIntegerField(editable=False)),
+                ('create_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
+                ('parent', mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='pivottable.Menu')),
+            ],
+            options={
+                'abstract': False,
+            },
+        ),
+    ]

+ 16 - 0
pivottable/migrations/0004_delete_menu.py

@@ -0,0 +1,16 @@
+# Generated by Django 3.0.8 on 2020-07-28 11:57
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('pivottable', '0003_menu'),
+    ]
+
+    operations = [
+        migrations.DeleteModel(
+            name='Menu',
+        ),
+    ]

BIN
pivottable/migrations/__pycache__/0001_initial.cpython-37.pyc


BIN
pivottable/migrations/__pycache__/0002_delete_menu.cpython-37.pyc


BIN
pivottable/migrations/__pycache__/0003_menu.cpython-37.pyc


BIN
pivottable/migrations/__pycache__/0004_delete_menu.cpython-37.pyc


+ 19 - 1
pivottable/models.py

@@ -1,6 +1,10 @@
+from django.contrib.auth.models import User
 from django.db import models
 
 # Create your models here.
+from mptt.fields import TreeForeignKey
+from mptt.models import MPTTModel
+
 
 class Payment(models.Model):
     payment_type = models.CharField(max_length=100)
@@ -15,4 +19,18 @@ class Payment(models.Model):
         app_label = 'payment'
         db_table = 'pay'
         verbose_name = '支出报表'
-        verbose_name_plural = '支出报表列表'
+        verbose_name_plural = '支出报表列表'
+
+class Menu(MPTTModel):
+    name = models.CharField(max_length=100)
+    config = models.TextField()
+    create_at = models.DateTimeField(auto_now_add=True)
+    create_by = models.ForeignKey(User, blank=True, null=True, on_delete=models.CASCADE)
+    parent = TreeForeignKey('self', blank=True, null=True, on_delete=models.CASCADE)
+    code = models.CharField(max_length=100)
+
+    class Meta:
+        app_label = 'basic'
+        db_table = 'basic_menu'
+        verbose_name = '报表菜单'
+        verbose_name_plural = '报表菜单列表'

+ 8 - 1
pivottable/serializer.py

@@ -2,7 +2,7 @@
 from rest_framework import serializers
 from rest_framework.serializers import ListSerializer
 
-from pivottable.models import Payment
+from pivottable.models import Payment, Menu
 
 
 class PaymentSerializer(serializers.ModelSerializer):
@@ -10,4 +10,11 @@ class PaymentSerializer(serializers.ModelSerializer):
         model = Payment
         # fields = ['url', 'username', 'email', 'is_staff']
         list_serializer = ListSerializer
+        fields = '__all__'
+
+class MenuSerializer(serializers.ModelSerializer):
+    class Meta:
+        model = Menu
+        # fields = ['url', 'username', 'email', 'is_staff']
+        list_serializer = ListSerializer
         fields = '__all__'

+ 10 - 0
pivottable/tests.py

@@ -1,3 +1,13 @@
+from threading import Thread
+
 from django.test import TestCase
 
 # Create your tests here.
+if __name__ == '__main__':
+    def forr(n, s):
+        for i in range(n):
+            print(s)
+    for i in range(30):
+        Thread(
+            forr(10, i)
+        ).start()

+ 4 - 3
pivottable/urls.py

@@ -13,16 +13,17 @@ Including another URLconf
     1. Import the include() function: from django.urls import include, path
     2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
 """
+from django.conf.urls import url
 from rest_framework_bulk.routes import BulkRouter
 
 # 给智能路由注册
-from pivottable.views import PaymentViews
+from pivottable.views import *
 
 router = BulkRouter()
 router.register(r'payment', PaymentViews)
-# router.register(r'post',PostViews)
+router.register(r'menu', MenuView)
 
 urlpatterns = router.urls
 urlpatterns += [
-
+    url(r'^paystat/', PayStatViews.as_view())
 ]

+ 28 - 4
pivottable/views.py

@@ -1,13 +1,37 @@
+from django.db.models import Sum, Count
 from django.shortcuts import render
 
 # Create your views here.
+from rest_framework import permissions, status
+from rest_framework.decorators import permission_classes
+from rest_framework.response import Response
+from rest_framework.views import APIView
 from rest_framework.viewsets import ModelViewSet
 
-from pivottable.models import Payment
-from pivottable.serializer import PaymentSerializer
-
+from pivottable.models import *
+from pivottable.serializer import *
 
+# @permission_classes((permissions.AllowAny,))
 class PaymentViews(ModelViewSet):
     pagination_class = None
     queryset = Payment.objects.all()
-    serializer_class = PaymentSerializer
+    serializer_class = PaymentSerializer
+    
+    
+
+# @permission_classes((permissions.AllowAny,))
+class MenuView(ModelViewSet):
+    queryset = Menu.objects.all()
+    serializer_class = MenuSerializer  # 序列化
+    pagination_class = None
+
+class PayStatViews(APIView):
+    # 统计 {order_by:0(默认0升序,1降序)}
+    def get(self, request):
+        data = request.GET
+        order_by = "price_sum"
+        if hasattr(data, "order_by") and data['order_by'] == 1:
+            order_by = "-price_sum"
+        data = Payment.objects.values('payment_type',price_sum=Sum('index_price'))\
+            .annotate(payment_type_count=Count('payment_type')).order_by(order_by)
+        return Response(data=data, status=status.HTTP_200_OK)

BIN
relation/__pycache__/views.cpython-37.pyc


+ 3 - 2
relation/views.py

@@ -1,11 +1,12 @@
 from django.shortcuts import render
 
 # Create your views here.
-from rest_framework import status
+
+from rest_framework import status, permissions
+from rest_framework.decorators import permission_classes
 from rest_framework.views import APIView
 from rest_framework.viewsets import ModelViewSet
 
-from relation.models import *
 from relation.serializer import *
 from rest_framework.response import Response
 

BIN
testthree/__pycache__/settings.cpython-37.pyc


BIN
workreport/__pycache__/urls.cpython-37.pyc


BIN
workreport/__pycache__/views.cpython-37.pyc