Kaynağa Gözat

Создание новых запросов и таблицы.

david.berlinskiy 1 yıl önce
ebeveyn
işleme
ba57d8ebe2

+ 3 - 1
admin/__init__.py

@@ -8,4 +8,6 @@ from .relationship import RelationshipAdmin
 from .resource import ResourceAdmin
 from .service import ServiceAdmin
 from .servicetype import ServiceTypeAdmin
-from .frequentaddress import FrequentaddressAdmin
+from .frequentaddress import FrequentaddressAdmin
+from .favoritecontacts import FavoritecontactsAdmin
+from .preferreddrivers import PreferreddriversAdmin

+ 12 - 0
admin/favoritecontacts.py

@@ -0,0 +1,12 @@
+from django.contrib import admin
+from metaservicesynced.models import Favoritecontacts
+
+@admin.register(Favoritecontacts)
+class FavoritecontactsAdmin(admin.ModelAdmin):
+    list_display = (
+        'id',
+        'client_id',
+        'full_name',
+        'phone_number',
+    )
+    list_filter = ('id','client_id')

+ 4 - 3
admin/frequentaddress.py

@@ -4,9 +4,10 @@ from metaservicesynced.models import Frequentaddress
 @admin.register(Frequentaddress)
 class FrequentaddressAdmin(admin.ModelAdmin):
     list_display = (
-        'id',
+        'client_id',
         'address',
         'description',
-        'user',
+        'id',
     )
-    list_filter = ('user', 'id')
+    list_filter = ('client_id', 'id')
+    

+ 11 - 0
admin/preferreddrivers.py

@@ -0,0 +1,11 @@
+from django.contrib import admin
+from metaservicesynced.models import Preferreddrivers
+
+@admin.register(Preferreddrivers)
+class PreferreddriversAdmin(admin.ModelAdmin):
+    list_display = (
+        'id',
+        'client_id',
+        'provider_id',
+    )
+    list_filter = ('id','client_id','provider_id')

+ 3 - 1
apiviews/__init__.py

@@ -9,4 +9,6 @@ from .resource import ResourceMVS
 from .service import ServiceMVS
 from .servicetype import ServiceTypeMVS
 from .personinfo import PersonInfoMVS
-from .frequentaddress import FrequentaddressMVS
+from .frequentaddress import FrequentaddressMVS
+from .favoritecontacts import FavoritecontactsMVS
+from .preferreddrivers import PreferreddriversMVS

+ 30 - 0
apiviews/favoritecontacts.py

@@ -0,0 +1,30 @@
+from django.db.models import CharField
+from django.db.models.functions import Cast
+from rest_framework import viewsets, permissions
+from rest_framework.response import Response
+from metaservicesynced.serializer import FavoritecontactsSerializer
+from metaservicesynced.models import Favoritecontacts
+
+class FavoritecontactsMVS(viewsets.ModelViewSet):
+    queryset = Favoritecontacts.objects.all()
+    serializer_class = FavoritecontactsSerializer
+    permission_classes = [permissions.IsAuthenticated]
+
+    def list(self, request, *args, **kwargs):
+        client_id = self.request.query_params.get('client_id')
+        queryset = Favoritecontacts.objects.all()
+        if client_id is not None:
+            queryset = queryset.annotate(client_id_int=Cast('client_id', output_field=CharField())).filter(client_id_int=client_id)
+        serializer = self.get_serializer(queryset, many=True)
+        return Response(serializer.data)
+    
+    def delete(self, request, *args, **kwargs):
+        client_id = self.request.query_params.get('client_id')
+        queryset = Favoritecontacts.objects.all()
+        if not client_id:
+            return Response({'error': 'client_id parameter is required'}, status=status.HTTP_400_BAD_REQUEST)
+        
+        queryset = queryset.annotate(client_id_int=Cast('client_id', output_field=CharField())).filter(client_id_int=client_id)
+        queryset.delete()
+
+        return Response({'message': f'Objects with client_id {client_id} were deleted'}, status=status.HTTP_204_NO_CONTENT)

+ 24 - 4
apiviews/frequentaddress.py

@@ -1,10 +1,30 @@
-from metaservicesynced.serializer import FrequentaddressSerializer
+from django.db.models import CharField
+from django.db.models.functions import Cast
 from rest_framework import viewsets, permissions
+from rest_framework.response import Response
+from metaservicesynced.serializer import FrequentaddressSerializer
 from metaservicesynced.models import Frequentaddress
 
 class FrequentaddressMVS(viewsets.ModelViewSet):
-
     queryset = Frequentaddress.objects.all()
     serializer_class = FrequentaddressSerializer
-    #permission_classes = [IsOwnerOrReadOnly]
-    permission_classes = [permissions.IsAuthenticated]
+    permission_classes = [permissions.IsAuthenticated]
+
+    def list(self, request, *args, **kwargs):
+        client_id = self.request.query_params.get('client_id')
+        queryset = Frequentaddress.objects.all()
+        if client_id is not None:
+            queryset = queryset.annotate(client_id_int=Cast('client_id', output_field=CharField())).filter(client_id_int=client_id)
+        serializer = self.get_serializer(queryset, many=True)
+        return Response(serializer.data)
+    
+    def delete(self, request, *args, **kwargs):
+        client_id = self.request.query_params.get('client_id')
+        queryset = Frequentaddress.objects.all()
+        if not client_id:
+            return Response({'error': 'client_id parameter is required'}, status=status.HTTP_400_BAD_REQUEST)
+        
+        queryset = queryset.annotate(client_id_int=Cast('client_id', output_field=CharField())).filter(client_id_int=client_id)
+        queryset.delete()
+
+        return Response({'message': f'Objects with client_id {client_id} were deleted'}, status=status.HTTP_204_NO_CONTENT)

+ 30 - 0
apiviews/preferreddrivers.py

@@ -0,0 +1,30 @@
+from django.db.models import CharField
+from django.db.models.functions import Cast
+from rest_framework import viewsets, permissions
+from rest_framework.response import Response
+from metaservicesynced.serializer import PreferreddriversSerializer
+from metaservicesynced.models import Preferreddrivers
+
+class PreferreddriversMVS(viewsets.ModelViewSet):
+    queryset = Preferreddrivers.objects.all()
+    serializer_class = PreferreddriversSerializer
+    permission_classes = [permissions.IsAuthenticated]
+
+    def list(self, request, *args, **kwargs):
+        client_id = self.request.query_params.get('client_id')
+        queryset = Preferreddrivers.objects.all()
+        if client_id is not None:
+            queryset = queryset.annotate(client_id_int=Cast('client_id', output_field=CharField())).filter(client_id_int=client_id)
+        serializer = self.get_serializer(queryset, many=True)
+        return Response(serializer.data)
+    
+    def delete(self, request, *args, **kwargs):
+        client_id = self.request.query_params.get('client_id')
+        queryset = Preferreddrivers.objects.all()
+        if not client_id:
+            return Response({'error': 'client_id parameter is required'}, status=status.HTTP_400_BAD_REQUEST)
+        
+        queryset = queryset.annotate(client_id_int=Cast('client_id', output_field=CharField())).filter(client_id_int=client_id)
+        queryset.delete()
+
+        return Response({'message': f'Objects with client_id {client_id} were deleted'}, status=status.HTTP_204_NO_CONTENT)

+ 3 - 1
models/__init__.py

@@ -8,4 +8,6 @@ from .relationship import Relationship
 from .resource import Resource
 from .service import Service
 from .servicetype import ServiceType
-from .frequentaddress import Frequentaddress
+from .frequentaddress import Frequentaddress
+from .favoritecontacts import Favoritecontacts
+from .preferreddrivers import Preferreddrivers

+ 11 - 0
models/favoritecontacts.py

@@ -0,0 +1,11 @@
+from django.db import models
+from tickets.models import Task
+
+class Favoritecontacts(models.Model):
+    client_id = models.IntegerField(help_text="id") 
+    phone_number = models.CharField(max_length=50,help_text="Номер телефона") 
+    full_name = models.CharField(max_length=100, help_text="Полное ФИО")
+    class Meta:
+        db_table = "favoritecontacts"
+        verbose_name = "Избранные контакты"
+        verbose_name_plural = "Избранные контакты"

+ 1 - 2
models/frequentaddress.py

@@ -1,9 +1,8 @@
 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="пользователь, которому соответствует роль клиента")
+    client_id = models.IntegerField(help_text="id клиента")
     address = models.CharField(max_length=150, help_text="Адрес")
     description = models.CharField(max_length=150, help_text="Описание")
     class Meta:

+ 10 - 0
models/preferreddrivers.py

@@ -0,0 +1,10 @@
+from django.db import models
+from tickets.models import Task
+
+class Preferreddrivers(models.Model):
+    client_id = models.IntegerField(help_text="Client id") 
+    provider_id = models.IntegerField(help_text="Provider id") 
+    class Meta:
+        db_table = "Prefereddrivers"
+        verbose_name = "Предпочтительные водители"
+        verbose_name_plural = "Предпочтительные водители"

+ 3 - 1
serializer/__init__.py

@@ -9,4 +9,6 @@ from .resource import ResourceSerializer
 from .service import ServiceSerializer
 from .servicetype import ServiceTypeSerializer
 from .personinfo import PersonInfoSerializer
-from .frequentaddress import FrequentaddressSerializer
+from .frequentaddress import FrequentaddressSerializer
+from .favoritecontacts import FavoritecontactsSerializer
+from .preferreddrivers import PreferreddriversSerializer

+ 7 - 0
serializer/favoritecontacts.py

@@ -0,0 +1,7 @@
+from rest_framework import serializers
+from metaservicesynced.models import Favoritecontacts
+
+class FavoritecontactsSerializer(serializers.ModelSerializer):
+    class Meta:
+        model = Favoritecontacts
+        fields= ['full_name','phone_number','id']

+ 1 - 1
serializer/frequentaddress.py

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

+ 7 - 0
serializer/preferreddrivers.py

@@ -0,0 +1,7 @@
+from rest_framework import serializers
+from metaservicesynced.models import Preferreddrivers
+
+class PreferreddriversSerializer(serializers.ModelSerializer):
+    class Meta:
+        model = Preferreddrivers
+        fields= ['provider_id','client_id','id']

+ 2 - 0
urls.py

@@ -15,6 +15,8 @@ router.register(r'service', ServiceMVS)
 router.register(r'servicetype', ServiceTypeMVS)
 router.register(r'personinfo', PersonInfoMVS)
 router.register(r'frequentaddress', FrequentaddressMVS)
+router.register(r'favoritecontacts', FavoritecontactsMVS)
+router.register(r'preferreddrivers', PreferreddriversMVS)
 urlpatterns = [  
     path('api/', include(router.urls), name="metasynced"),
 ]