completed PsychTestAddResultViewSet
This commit is contained in:
parent
9826aea0c1
commit
c528c6b182
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,27 @@
|
|||
# Generated by Django 4.2.1 on 2023-05-12 12:45
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pairent_app', '0004_apartament_lastprice'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='User',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('favorites_apartaments', 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': 'Пользователи',
|
||||
},
|
||||
),
|
||||
]
|
|
@ -21,4 +21,4 @@ class ApartamentDetailSerializer(serializers.ModelSerializer):
|
|||
class PsychTestAddResultSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = "psych_test_result"
|
||||
fields = ("psych_test_result",)
|
|
@ -9,5 +9,5 @@ urlpatterns = format_suffix_patterns([
|
|||
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/filters/", views.ApartmentFilter.as_view({'post': 'list'})),
|
||||
path("psych_test/add_result/<int:pk>", views.PsychTestAddResultViewSet.as_view({'post': 'update'}))
|
||||
path("psych_test/add_result/<int:pk>", views.PsychTestAddResultViewSet.as_view({'patch': 'update'})) # пример: psych_test/add_result/1/?result=50 result - результат псих теста пользователя
|
||||
])
|
||||
|
|
|
@ -83,11 +83,12 @@ class ApartmentFilter(viewsets.ViewSet):
|
|||
return Response(ApartamentListSerializer(filtered, many=True).data);
|
||||
|
||||
|
||||
# TODO: доделать
|
||||
class PsychTestAddResultViewSet(viewsets.ViewSet):
|
||||
def update(self, request):
|
||||
def get_object(self, pk):
|
||||
return User.objects.filter(pk=pk)
|
||||
def update(self, request, pk):
|
||||
user = self.get_object(pk)
|
||||
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)
|
||||
return Response(PsychTestAddResultSerializer(User.objects.get(pk=pk)).data)
|
||||
|
Loading…
Reference in New Issue