Quellcode durchsuchen

Добавление новоq таблицы и запросов

david.berlinskiy vor 1 Jahr
Ursprung
Commit
0e6081cdf6

+ 2 - 1
admin/__init__.py

@@ -7,4 +7,5 @@ from .provider import ProviderAdmin
 from .relationship import RelationshipAdmin
 from .resource import ResourceAdmin
 from .service import ServiceAdmin
-from .servicetype import ServiceTypeAdmin
+from .servicetype import ServiceTypeAdmin
+from .frequentaddress import FrequentaddressAdmin

+ 12 - 0
admin/frequentaddress.py

@@ -0,0 +1,12 @@
+from django.contrib import admin
+from metaservicesynced.models import Frequentaddress
+
+@admin.register(Frequentaddress)
+class FrequentaddressAdmin(admin.ModelAdmin):
+    list_display = (
+        'id',
+        'address',
+        'description',
+        'user',
+    )
+    list_filter = ('user', 'id')

+ 2 - 1
apiviews/__init__.py

@@ -8,4 +8,5 @@ from .relationship import RelationshipMVS
 from .resource import ResourceMVS
 from .service import ServiceMVS
 from .servicetype import ServiceTypeMVS
-from .personinfo import PersonInfoMVS
+from .personinfo import PersonInfoMVS
+from .frequentaddress import FrequentaddressMVS

+ 10 - 0
apiviews/frequentaddress.py

@@ -0,0 +1,10 @@
+from metaservicesynced.serializer import FrequentaddressSerializer
+from rest_framework import viewsets, permissions
+from metaservicesynced.models import Frequentaddress
+
+class FrequentaddressMVS(viewsets.ModelViewSet):
+
+    queryset = Frequentaddress.objects.all()
+    serializer_class = FrequentaddressSerializer
+    #permission_classes = [IsOwnerOrReadOnly]
+    permission_classes = [permissions.IsAuthenticated]

+ 3 - 5
apiviews/personinfo.py

@@ -1,10 +1,8 @@
 from metaservicesynced.serializer import PersonInfoSerializer
 from rest_framework import viewsets, permissions
-from metaservicesynced.models import PersonInfo
+from SharixAdmin.models import SharixUser
 
-class PersonInfoMVS(viewsets.ModelViewSet):
-
-    queryset = PersonInfo.objects.all()
+class PersonInfoMVS(viewsets.ReadOnlyModelViewSet): 
+    queryset = SharixUser.objects.all()
     serializer_class = PersonInfoSerializer
-    #permission_classes = [IsOwnerOrReadOnly]
     permission_classes = [permissions.IsAuthenticated]

+ 1 - 1
models/__init__.py

@@ -8,4 +8,4 @@ from .relationship import Relationship
 from .resource import Resource
 from .service import Service
 from .servicetype import ServiceType
-from .personinfo import PersonInfo
+from .frequentaddress import Frequentaddress

+ 12 - 0
models/frequentaddress.py

@@ -0,0 +1,12 @@
+from django.db import models
+from SharixAdmin.models import SharixUser
+from tickets.models import Task
+
+class Frequentaddress(models.Model):
+    user = models.ForeignKey(SharixUser, on_delete=models.DO_NOTHING, help_text="пользователь, которому соответствует роль клиента")
+    address = models.CharField(max_length=150, help_text="Адрес")
+    description = models.CharField(max_length=150, help_text="Описание")
+    class Meta:
+        db_table = "frequentaddress"
+        verbose_name = "Частые адреса"
+        verbose_name_plural = "Частые адреса"

+ 0 - 12
models/personinfo.py

@@ -1,12 +0,0 @@
-from django.db import models
-from SharixAdmin.models import SharixUser
-from tickets.models import Task
-
-class PersonInfo(models.Model):
-    last_name = models.CharField(max_length=150, help_text="Фамилия пользователя")
-    first_name = models.CharField(max_length=150, help_text="Имя пользователя")
-
-    class Meta:
-        db_table = "auth_user"
-        verbose_name = "Пользователя"
-        verbose_name_plural = "Пользователи"

+ 2 - 1
serializer/__init__.py

@@ -8,4 +8,5 @@ from .relationship import RelationshipSerializer
 from .resource import ResourceSerializer
 from .service import ServiceSerializer
 from .servicetype import ServiceTypeSerializer
-from .personinfo import PersonInfoSerializer
+from .personinfo import PersonInfoSerializer
+from .frequentaddress import FrequentaddressSerializer

+ 7 - 0
serializer/frequentaddress.py

@@ -0,0 +1,7 @@
+from rest_framework import serializers
+from metaservicesynced.models import Frequentaddress
+
+class FrequentaddressSerializer(serializers.ModelSerializer):
+    class Meta:
+        model = Frequentaddress
+        exclude = ["id"]

+ 8 - 3
serializer/personinfo.py

@@ -1,7 +1,12 @@
 from rest_framework import serializers
-from metaservicesynced.models import PersonInfo
+from SharixAdmin.models import SharixUser
 
 class PersonInfoSerializer(serializers.ModelSerializer):
+    full_name = serializers.ReadOnlyField()
+
     class Meta:
-        model = PersonInfo
-        exclude = ["id"]
+        model = SharixUser
+        fields = ['full_name']
+
+    def validate(self, attrs):
+        return super().validate(attrs)

+ 1 - 0
urls.py

@@ -14,6 +14,7 @@ router.register(r'resource', ResourceMVS)
 router.register(r'service', ServiceMVS)
 router.register(r'servicetype', ServiceTypeMVS)
 router.register(r'personinfo', PersonInfoMVS)
+router.register(r'frequentaddress', FrequentaddressMVS)
 urlpatterns = [  
     path('api/', include(router.urls), name="metasynced"),
 ]