From 4645bdedfa52ba0038f4c12172134c462148a225 Mon Sep 17 00:00:00 2001 From: Ankur Date: Wed, 8 Nov 2023 19:47:18 +0100 Subject: [PATCH] Depth --- .../serializers/position_serializer.py | 6 +++ src/involvement/urls.py | 1 + src/involvement/views/position_api.py | 6 ++- src/moore/settings/dev.py | 40 +++++++++---------- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/involvement/serializers/position_serializer.py b/src/involvement/serializers/position_serializer.py index 968cd965..bc5d9d92 100644 --- a/src/involvement/serializers/position_serializer.py +++ b/src/involvement/serializers/position_serializer.py @@ -5,3 +5,9 @@ class PositionSerializer(serializers.ModelSerializer): class Meta: model = Position fields = '__all__' + +class PositionDepthSerializer(serializers.ModelSerializer): + class Meta: + model = Position + fields = '__all__' + depth = 1 diff --git a/src/involvement/urls.py b/src/involvement/urls.py index 3b9f56f4..b1929946 100644 --- a/src/involvement/urls.py +++ b/src/involvement/urls.py @@ -4,6 +4,7 @@ router = routers.SimpleRouter() router.register(r'^position', views.position_api.PositionViewSet, basename="PositionView") +router.register(r'^position2', views.position_api.Position2ViewSet, basename="Position2View") urlpatterns = [ re_path( diff --git a/src/involvement/views/position_api.py b/src/involvement/views/position_api.py index a98a02d9..c6ced2e1 100644 --- a/src/involvement/views/position_api.py +++ b/src/involvement/views/position_api.py @@ -1,5 +1,5 @@ from rest_framework import viewsets -from involvement.serializers.position_serializer import PositionSerializer +from involvement.serializers.position_serializer import PositionSerializer, PositionDepthSerializer from rest_framework.permissions import AllowAny from involvement.models.position import Position @@ -8,3 +8,7 @@ class PositionViewSet(viewsets.ModelViewSet): permission_classes = [AllowAny] queryset = Position.objects.all() +class Position2ViewSet(viewsets.ModelViewSet): + serializer_class = PositionDepthSerializer + permission_classes = [AllowAny] + queryset = Position.objects.all() diff --git a/src/moore/settings/dev.py b/src/moore/settings/dev.py index d6e2ea99..81c29ed4 100644 --- a/src/moore/settings/dev.py +++ b/src/moore/settings/dev.py @@ -21,31 +21,31 @@ # https://docs.djangoproject.com/en/1.10/ref/settings/#databases -if IS_RUNNING_TEST: - DATABASES = { +# if IS_RUNNING_TEST: +DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } - # Override search backend to not use postgres - WAGTAILSEARCH_BACKENDS = { - 'default': { - 'BACKEND': 'wagtail.search.backends.database', - } - } - -elif 'DOCKER' in os.environ: - DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'moore', - 'USER': 'moore', - 'HOST': 'moore-db', - 'PASSWORD': 'moore', - 'PORT': 5432, - } - } + # # Override search backend to not use postgres + # WAGTAILSEARCH_BACKENDS = { + # 'default': { + # 'BACKEND': 'wagtail.search.backends.database', + # } + # } + +# elif 'DOCKER' in os.environ: +# DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.postgresql', +# 'NAME': 'moore', +# 'USER': 'moore', +# 'HOST': 'moore-db', +# 'PASSWORD': 'moore', +# 'PORT': 5432, +# } +# } # Base URL to use when referring to full URLs within the Wagtail admin # backend - e.g. in notification emails. Don't include '/admin' or a