diff --git a/service/admin.py b/service/admin.py index 0173cba..2166858 100644 --- a/service/admin.py +++ b/service/admin.py @@ -63,6 +63,7 @@ class CategoryAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): obj.save() cache.clear() + run_psql_command() def delete_model(self, request, obj): obj.delete() @@ -71,16 +72,16 @@ class CategoryAdmin(admin.ModelAdmin): class PostPvzCategoryAdmin(CategoryAdmin): def get_readonly_fields(self, request, obj=None): - if obj.id in (1, 2): + if obj and obj.id in (1, 2): return ['id', 'name'] else: return super().get_readonly_fields(request, obj) def save_model(self, request, obj, form, change): obj.save() - run_psql_command() if 'include_in_ml' in form.changed_data or 'visible' in form.changed_data: LayerService.update_categories(obj) + run_psql_command() cache.clear() def delete_model(self, request, obj): @@ -96,6 +97,7 @@ class GroupAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): obj.save() cache.clear() + run_psql_command() def delete_model(self, request, obj): obj.delete() @@ -104,16 +106,16 @@ class GroupAdmin(admin.ModelAdmin): class PostPvzGroupAdmin(GroupAdmin): def get_readonly_fields(self, request, obj=None): - if obj.id in (7, 8, 9, 10, 12, 17, 19, 20, 24, 25): + if obj and obj.id in (7, 8, 9, 10, 12, 17, 19, 20, 24, 25): return ['id', 'name'] else: return super().get_readonly_fields(request, obj) def save_model(self, request, obj, form, change): obj.save() - run_psql_command() if 'include_in_ml' in form.changed_data or 'visible' in form.changed_data: LayerService.update_groups(obj) + run_psql_command() cache.clear() def delete_model(self, request, obj): @@ -126,7 +128,7 @@ class PostPvzGroupAdmin(GroupAdmin): class OtherObjectsGroupAdmin(GroupAdmin): def get_readonly_fields(self, request, obj=None): - if obj.id in (4, 5) or obj.id in list(range(22, 43)): + if obj and (obj.id in (4, 5) or obj.id in list(range(22, 43))): return ['id', 'name'] else: return super().get_readonly_fields(request, obj) @@ -140,7 +142,7 @@ class OtherObjectsGroupAdmin(GroupAdmin): class OtherObjectsCategoryAdmin(CategoryAdmin): def get_readonly_fields(self, request, obj=None): - if obj.id in (4, 5) or obj.id in list(range(22, 43)): + if obj and (obj.id in (4, 5) or obj.id in list(range(22, 43))): return ['id', 'name'] else: return super().get_readonly_fields(request, obj) diff --git a/service/tasks.py b/service/tasks.py index 77e0a8e..bf0c696 100644 --- a/service/tasks.py +++ b/service/tasks.py @@ -443,6 +443,7 @@ def load_post_and_pvz(obj_id: int): status.status = "Завершено" cache.clear() status.save() + run_psql_command() @@ -486,6 +487,7 @@ def load_other_objects(obj_id: int): status.status = "Загрузка данных завершена" cache.clear() status.save() + run_psql_command() @shared_task() diff --git a/service/views.py b/service/views.py index 417e5c8..7acc1a3 100644 --- a/service/views.py +++ b/service/views.py @@ -28,7 +28,7 @@ from django.shortcuts import redirect from django.contrib import messages from django_filters.rest_framework import DjangoFilterBackend from rest_framework import filters -from service.utils import CustomReadOnlyModelViewSet +from service.utils import CustomReadOnlyModelViewSet, run_psql_command from django.db.models import Min, Max import os from django.forms.models import model_to_dict @@ -279,6 +279,7 @@ class PlacementPointViewSet(ReadOnlyModelViewSet): return Response({'message': 'No status'}, HTTPStatus.BAD_REQUEST) PointService.update_points_in_radius(qs, new_status) PointService.update_status(qs, new_status) + run_psql_command() return Response( {'message': 'status updated'}, status=HTTPStatus.OK, @@ -467,7 +468,6 @@ class AvgBiValuesViewSet(APIView): return Response(data, status=HTTPStatus.OK) - @api_view(['POST']) def upload_post_and_pvz(request): warnings.filterwarnings('ignore')