add psych_test_result column in User model; start made PsychTestAddResultViewSet

This commit is contained in:
Денис Сарапулов 2023-05-12 22:10:12 +10:00
parent db071362cb
commit c4637eed7a
8 changed files with 31 additions and 7 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

BIN
pairent_backend/.DS_Store vendored Normal file

Binary file not shown.

BIN
pairent_backend/pairent_app/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -1,5 +1,6 @@
# Generated by Django 4.2.1 on 2023-05-08 16:44 # Generated by Django 4.2.1 on 2023-05-12 11:50
import django.core.validators
from django.db import migrations, models from django.db import migrations, models
@ -16,11 +17,16 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('favorites_apartaments', models.CharField(max_length=100, verbose_name='Избранные квартиры')), ('favorites_apartaments', models.CharField(max_length=100, verbose_name='Избранные квартиры')),
('apartaments_for_comparison', models.CharField(max_length=100, verbose_name='Квартиры для сравнения')), ('apartaments_for_comparison', models.CharField(max_length=100, verbose_name='Квартиры для сравнения')),
('psych_test_result', models.IntegerField(null=True, validators=[django.core.validators.MaxValueValidator(100)], verbose_name='Результат психологического теста')),
], ],
options={
'verbose_name': 'Пользователь',
'verbose_name_plural': 'Пользователи',
},
), ),
migrations.RemoveField( migrations.RemoveField(
model_name='apartament', model_name='apartament',
name='isСhild', name='isChild',
), ),
migrations.AlterField( migrations.AlterField(
model_name='apartament', model_name='apartament',

View File

@ -84,6 +84,7 @@ class User(models.Model):
"""Тестовая модель данных для избранных и сравнения""" """Тестовая модель данных для избранных и сравнения"""
favorites_apartaments = models.CharField(max_length=100, verbose_name="Избранные квартиры") favorites_apartaments = models.CharField(max_length=100, verbose_name="Избранные квартиры")
apartaments_for_comparison = models.CharField(max_length=100, verbose_name="Квартиры для сравнения") apartaments_for_comparison = models.CharField(max_length=100, verbose_name="Квартиры для сравнения")
psych_test_result = models.IntegerField(validators=[MaxValueValidator(100)], null=True, verbose_name="Результат психологического теста")
class Meta: class Meta:
verbose_name = "Пользователь" verbose_name = "Пользователь"

View File

@ -1,6 +1,6 @@
from rest_framework import serializers from rest_framework import serializers
from .models import Apartament from .models import Apartament, User
class ApartamentListSerializer(serializers.ModelSerializer): class ApartamentListSerializer(serializers.ModelSerializer):
@ -17,3 +17,8 @@ class ApartamentDetailSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Apartament model = Apartament
fields = "__all__" fields = "__all__"
class PsychTestAddResultSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = "psych_test_result"

View File

@ -8,5 +8,6 @@ urlpatterns = format_suffix_patterns([
path("apartament/<int:pk>/", views.ApartamentViewSet.as_view({'get': 'retrieve'})), path("apartament/<int:pk>/", views.ApartamentViewSet.as_view({'get': 'retrieve'})),
path("apartaments/comparison/", views.ApartamentGetManyViewSet.as_view({'get': 'retrieve'})), # пример: apartaments/comparison/?user_id=1 user_id - id пользователя path("apartaments/comparison/", views.ApartamentGetManyViewSet.as_view({'get': 'retrieve'})), # пример: apartaments/comparison/?user_id=1 user_id - id пользователя
path("apartaments/favorite/", views.ApartamentGetManyViewSet.as_view({'get': 'list'})), # пример: apartaments/favorite/?user_id=1 user_id - id пользователя path("apartaments/favorite/", views.ApartamentGetManyViewSet.as_view({'get': 'list'})), # пример: apartaments/favorite/?user_id=1 user_id - id пользователя
path("apartaments/filters/", views.ApartmentFilter.as_view({'post': 'list'})) path("apartaments/filters/", views.ApartmentFilter.as_view({'post': 'list'})),
path("psych_test/add_result/<int:pk>", views.PsychTestAddResultViewSet.as_view({'post': 'update'}))
]) ])

View File

@ -7,7 +7,8 @@ from django.http import HttpResponseBadRequest
from .models import Apartament, User from .models import Apartament, User
from .serializer import (ApartamentListSerializer, from .serializer import (ApartamentListSerializer,
ApartamentDetailSerializer) ApartamentDetailSerializer,
PsychTestAddResultSerializer)
import json import json
@ -80,3 +81,13 @@ class ApartmentFilter(viewsets.ViewSet):
filtered.append(entry); filtered.append(entry);
return Response(ApartamentListSerializer(filtered, many=True).data); return Response(ApartamentListSerializer(filtered, many=True).data);
# TODO: доделать
class PsychTestAddResultViewSet(viewsets.ViewSet):
def update(self, request):
result = request.query_params.get("result", None)
user = User.User.objects.filter(pk=self.kwargs['pk'])
user.update(psych_test_result=result)
return Response(PsychTestAddResultSerializer(user).data)