From c36a2318a18081cef23fc27f32c486181186680d Mon Sep 17 00:00:00 2001 From: Husanjonazamov Date: Fri, 13 Feb 2026 17:22:47 +0500 Subject: [PATCH] AutoEvaluationModel qoshildi yani bu valuation bilan vehicle ni asosiy ulab beradigan model --- core/apps/evaluation/admin/__init__.py | 1 + core/apps/evaluation/admin/auto.py | 12 +++ core/apps/evaluation/filters/__init__.py | 1 + core/apps/evaluation/filters/auto.py | 13 +++ core/apps/evaluation/forms/__init__.py | 1 + core/apps/evaluation/forms/auto.py | 10 ++ .../migrations/0004_autoevaluationmodel.py | 29 +++++ core/apps/evaluation/models/__init__.py | 2 + core/apps/evaluation/models/auto.py | 37 +++++++ core/apps/evaluation/permissions/__init__.py | 1 + core/apps/evaluation/permissions/auto.py | 12 +++ core/apps/evaluation/serializers/__init__.py | 1 + .../serializers/auto/AutoEvaluation.py | 28 +++++ .../evaluation/serializers/auto/__init__.py | 1 + core/apps/evaluation/signals/__init__.py | 1 + core/apps/evaluation/signals/auto.py | 8 ++ core/apps/evaluation/tests/__init__.py | 1 + core/apps/evaluation/tests/auto/__init__.py | 1 + .../tests/auto/test_AutoEvaluation.py | 101 ++++++++++++++++++ core/apps/evaluation/translation/__init__.py | 1 + core/apps/evaluation/translation/auto.py | 8 ++ core/apps/evaluation/urls.py | 3 +- core/apps/evaluation/validators/__init__.py | 1 + core/apps/evaluation/validators/auto.py | 8 ++ core/apps/evaluation/views/__init__.py | 1 + core/apps/evaluation/views/auto.py | 25 +++++ 26 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 core/apps/evaluation/admin/auto.py create mode 100644 core/apps/evaluation/filters/auto.py create mode 100644 core/apps/evaluation/forms/auto.py create mode 100644 core/apps/evaluation/migrations/0004_autoevaluationmodel.py create mode 100644 core/apps/evaluation/models/auto.py create mode 100644 core/apps/evaluation/permissions/auto.py create mode 100644 core/apps/evaluation/serializers/auto/AutoEvaluation.py create mode 100644 core/apps/evaluation/serializers/auto/__init__.py create mode 100644 core/apps/evaluation/signals/auto.py create mode 100644 core/apps/evaluation/tests/auto/__init__.py create mode 100644 core/apps/evaluation/tests/auto/test_AutoEvaluation.py create mode 100644 core/apps/evaluation/translation/auto.py create mode 100644 core/apps/evaluation/validators/auto.py create mode 100644 core/apps/evaluation/views/auto.py diff --git a/core/apps/evaluation/admin/__init__.py b/core/apps/evaluation/admin/__init__.py index 9683ac0..a21258a 100644 --- a/core/apps/evaluation/admin/__init__.py +++ b/core/apps/evaluation/admin/__init__.py @@ -1,3 +1,4 @@ +from .auto import * # noqa from .customer import * # noqa from .valuation import * # noqa from .vehicle import * # noqa diff --git a/core/apps/evaluation/admin/auto.py b/core/apps/evaluation/admin/auto.py new file mode 100644 index 0000000..3b4ab5c --- /dev/null +++ b/core/apps/evaluation/admin/auto.py @@ -0,0 +1,12 @@ +from django.contrib import admin +from unfold.admin import ModelAdmin + +from core.apps.evaluation.models import AutoEvaluationModel + + +@admin.register(AutoEvaluationModel) +class AutoevaluationAdmin(ModelAdmin): + list_display = ( + "id", + "__str__", + ) diff --git a/core/apps/evaluation/filters/__init__.py b/core/apps/evaluation/filters/__init__.py index 9683ac0..a21258a 100644 --- a/core/apps/evaluation/filters/__init__.py +++ b/core/apps/evaluation/filters/__init__.py @@ -1,3 +1,4 @@ +from .auto import * # noqa from .customer import * # noqa from .valuation import * # noqa from .vehicle import * # noqa diff --git a/core/apps/evaluation/filters/auto.py b/core/apps/evaluation/filters/auto.py new file mode 100644 index 0000000..d73bb5b --- /dev/null +++ b/core/apps/evaluation/filters/auto.py @@ -0,0 +1,13 @@ +# from django_filters import rest_framework as filters + +# from core.apps.evaluation.models import AutoEvaluationModel + + +# class AutoevaluationFilter(filters.FilterSet): +# # name = filters.CharFilter(field_name="name", lookup_expr="icontains") + +# class Meta: +# model = AutoEvaluationModel +# fields = [ +# "name", +# ] diff --git a/core/apps/evaluation/forms/__init__.py b/core/apps/evaluation/forms/__init__.py index 9683ac0..a21258a 100644 --- a/core/apps/evaluation/forms/__init__.py +++ b/core/apps/evaluation/forms/__init__.py @@ -1,3 +1,4 @@ +from .auto import * # noqa from .customer import * # noqa from .valuation import * # noqa from .vehicle import * # noqa diff --git a/core/apps/evaluation/forms/auto.py b/core/apps/evaluation/forms/auto.py new file mode 100644 index 0000000..34d0ddf --- /dev/null +++ b/core/apps/evaluation/forms/auto.py @@ -0,0 +1,10 @@ +from django import forms + +from core.apps.evaluation.models import AutoEvaluationModel + + +class AutoevaluationForm(forms.ModelForm): + + class Meta: + model = AutoEvaluationModel + fields = "__all__" diff --git a/core/apps/evaluation/migrations/0004_autoevaluationmodel.py b/core/apps/evaluation/migrations/0004_autoevaluationmodel.py new file mode 100644 index 0000000..b262630 --- /dev/null +++ b/core/apps/evaluation/migrations/0004_autoevaluationmodel.py @@ -0,0 +1,29 @@ +# Generated by Django 5.2.7 on 2026-02-13 12:19 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('evaluation', '0003_vehiclemodel_valuationmodel'), + ] + + operations = [ + migrations.CreateModel( + name='AutoEvaluationModel', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('valuation', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='auto_detail', to='evaluation.valuationmodel', verbose_name='valuation')), + ('vehicle', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='evaluation', to='evaluation.vehiclemodel', verbose_name='vehicle')), + ], + options={ + 'verbose_name': 'Auto Evaluation', + 'verbose_name_plural': 'Auto Evaluations', + 'db_table': 'AutoEvaluation', + }, + ), + ] diff --git a/core/apps/evaluation/models/__init__.py b/core/apps/evaluation/models/__init__.py index 9683ac0..e516473 100644 --- a/core/apps/evaluation/models/__init__.py +++ b/core/apps/evaluation/models/__init__.py @@ -1,3 +1,5 @@ +from .auto import * # noqa from .customer import * # noqa from .valuation import * # noqa from .vehicle import * # noqa +from .auto import * # noqa diff --git a/core/apps/evaluation/models/auto.py b/core/apps/evaluation/models/auto.py new file mode 100644 index 0000000..d5771d6 --- /dev/null +++ b/core/apps/evaluation/models/auto.py @@ -0,0 +1,37 @@ +from django.db import models +from django.utils.translation import gettext_lazy as _ +from django_core.models import AbstractBaseModel +from model_bakery import baker + + +from .valuation import ValuationModel +from .vehicle import VehicleModel + + +class AutoEvaluationModel(AbstractBaseModel): + valuation = models.OneToOneField( + ValuationModel, + on_delete=models.CASCADE, + related_name="auto_detail", + verbose_name=_("valuation"), + ) + vehicle = models.OneToOneField( + VehicleModel, + on_delete=models.CASCADE, + related_name="evaluation", + verbose_name=_("vehicle"), + ) + + def __str__(self): + return f"Auto Evaluation for {self.valuation}" + + + @classmethod + def _baker(cls): + return baker.make(cls) + + class Meta: + db_table = "AutoEvaluation" + verbose_name = _("Auto Evaluation") + verbose_name_plural = _("Auto Evaluations") + diff --git a/core/apps/evaluation/permissions/__init__.py b/core/apps/evaluation/permissions/__init__.py index 9683ac0..a21258a 100644 --- a/core/apps/evaluation/permissions/__init__.py +++ b/core/apps/evaluation/permissions/__init__.py @@ -1,3 +1,4 @@ +from .auto import * # noqa from .customer import * # noqa from .valuation import * # noqa from .vehicle import * # noqa diff --git a/core/apps/evaluation/permissions/auto.py b/core/apps/evaluation/permissions/auto.py new file mode 100644 index 0000000..ab08a3e --- /dev/null +++ b/core/apps/evaluation/permissions/auto.py @@ -0,0 +1,12 @@ +from rest_framework import permissions + + +class AutoevaluationPermission(permissions.BasePermission): + + def __init__(self) -> None: ... + + def __call__(self, *args, **kwargs): + return self + + def has_permission(self, request, view): + return True diff --git a/core/apps/evaluation/serializers/__init__.py b/core/apps/evaluation/serializers/__init__.py index 9683ac0..a21258a 100644 --- a/core/apps/evaluation/serializers/__init__.py +++ b/core/apps/evaluation/serializers/__init__.py @@ -1,3 +1,4 @@ +from .auto import * # noqa from .customer import * # noqa from .valuation import * # noqa from .vehicle import * # noqa diff --git a/core/apps/evaluation/serializers/auto/AutoEvaluation.py b/core/apps/evaluation/serializers/auto/AutoEvaluation.py new file mode 100644 index 0000000..e8221d1 --- /dev/null +++ b/core/apps/evaluation/serializers/auto/AutoEvaluation.py @@ -0,0 +1,28 @@ +from rest_framework import serializers + +from core.apps.evaluation.models import AutoEvaluationModel + + +class BaseAutoevaluationSerializer(serializers.ModelSerializer): + class Meta: + model = AutoEvaluationModel + fields = [ + "id", + "valuation", + ] + + +class ListAutoevaluationSerializer(BaseAutoevaluationSerializer): + class Meta(BaseAutoevaluationSerializer.Meta): ... + + +class RetrieveAutoevaluationSerializer(BaseAutoevaluationSerializer): + class Meta(BaseAutoevaluationSerializer.Meta): ... + + +class CreateAutoevaluationSerializer(BaseAutoevaluationSerializer): + class Meta(BaseAutoevaluationSerializer.Meta): + fields = [ + "id", + "valuation", + ] diff --git a/core/apps/evaluation/serializers/auto/__init__.py b/core/apps/evaluation/serializers/auto/__init__.py new file mode 100644 index 0000000..07a3169 --- /dev/null +++ b/core/apps/evaluation/serializers/auto/__init__.py @@ -0,0 +1 @@ +from .AutoEvaluation import * # noqa diff --git a/core/apps/evaluation/signals/__init__.py b/core/apps/evaluation/signals/__init__.py index 9683ac0..a21258a 100644 --- a/core/apps/evaluation/signals/__init__.py +++ b/core/apps/evaluation/signals/__init__.py @@ -1,3 +1,4 @@ +from .auto import * # noqa from .customer import * # noqa from .valuation import * # noqa from .vehicle import * # noqa diff --git a/core/apps/evaluation/signals/auto.py b/core/apps/evaluation/signals/auto.py new file mode 100644 index 0000000..e245c9b --- /dev/null +++ b/core/apps/evaluation/signals/auto.py @@ -0,0 +1,8 @@ +from django.db.models.signals import post_save +from django.dispatch import receiver + +from core.apps.evaluation.models import AutoEvaluationModel + + +@receiver(post_save, sender=AutoEvaluationModel) +def AutoevaluationSignal(sender, instance, created, **kwargs): ... diff --git a/core/apps/evaluation/tests/__init__.py b/core/apps/evaluation/tests/__init__.py index 9683ac0..a21258a 100644 --- a/core/apps/evaluation/tests/__init__.py +++ b/core/apps/evaluation/tests/__init__.py @@ -1,3 +1,4 @@ +from .auto import * # noqa from .customer import * # noqa from .valuation import * # noqa from .vehicle import * # noqa diff --git a/core/apps/evaluation/tests/auto/__init__.py b/core/apps/evaluation/tests/auto/__init__.py new file mode 100644 index 0000000..6dde8a4 --- /dev/null +++ b/core/apps/evaluation/tests/auto/__init__.py @@ -0,0 +1 @@ +from .test_AutoEvaluation import * # noqa diff --git a/core/apps/evaluation/tests/auto/test_AutoEvaluation.py b/core/apps/evaluation/tests/auto/test_AutoEvaluation.py new file mode 100644 index 0000000..c94e9a7 --- /dev/null +++ b/core/apps/evaluation/tests/auto/test_AutoEvaluation.py @@ -0,0 +1,101 @@ +import pytest +from django.urls import reverse +from rest_framework.test import APIClient + +from core.apps.evaluation.models import AutoEvaluationModel + + +@pytest.fixture +def instance(db): + return AutoEvaluationModel._baker() + + +@pytest.fixture +def api_client(instance): + client = APIClient() + ##client.force_authenticate(user=instance.user) + return client, instance + + +@pytest.fixture +def data(api_client): + client, instance = api_client + return ( + { + "list": reverse("auto-evaluation-list"), + "retrieve": reverse("auto-evaluation-detail", kwargs={"pk": instance.pk}), + "retrieve-not-found": reverse("auto-evaluation-detail", kwargs={"pk": 1000}), + }, + client, + instance, + ) + + +@pytest.mark.django_db +def test_list(data): + urls, client, _ = data + response = client.get(urls["list"]) + data_resp = response.json() + assert response.status_code == 200 + assert data_resp["status"] is True + + +@pytest.mark.django_db +def test_retrieve(data): + urls, client, _ = data + response = client.get(urls["retrieve"]) + data_resp = response.json() + assert response.status_code == 200 + assert data_resp["status"] is True + + +@pytest.mark.django_db +def test_retrieve_not_found(data): + urls, client, _ = data + response = client.get(urls["retrieve-not-found"]) + data_resp = response.json() + assert response.status_code == 404 + assert data_resp["status"] is False + + +# @pytest.mark.django_db +# def test_create(data): +# urls, client, _ = data +# response = client.post(urls["list"], data={"name": "test"}) +# assert response.json()["status"] is True +# assert response.status_code == 201 + + +# @pytest.mark.django_db +# def test_update(data): +# urls, client, _ = data +# response = client.patch(urls["retrieve"], data={"name": "updated"}) +# assert response.json()["status"] is True +# assert response.status_code == 200 +# +# # verify updated value +# response = client.get(urls["retrieve"]) +# assert response.json()["status"] is True +# assert response.status_code == 200 +# assert response.json()["data"]["name"] == "updated" + + +# @pytest.mark.django_db +# def test_partial_update(): +# urls, client, _ = data +# response = client.patch(urls["retrieve"], data={"name": "updated"}) +# assert response.json()["status"] is True +# assert response.status_code == 200 +# +# # verify updated value +# response = client.get(urls["retrieve"]) +# assert response.json()["status"] is True +# assert response.status_code == 200 +# assert response.json()["data"]["name"] == "updated" + + +# @pytest.mark.django_db +# def test_destroy(data): +# urls, client, _ = data +# response = client.delete(urls["retrieve"]) +# assert response.status_code == 204 diff --git a/core/apps/evaluation/translation/__init__.py b/core/apps/evaluation/translation/__init__.py index 9683ac0..a21258a 100644 --- a/core/apps/evaluation/translation/__init__.py +++ b/core/apps/evaluation/translation/__init__.py @@ -1,3 +1,4 @@ +from .auto import * # noqa from .customer import * # noqa from .valuation import * # noqa from .vehicle import * # noqa diff --git a/core/apps/evaluation/translation/auto.py b/core/apps/evaluation/translation/auto.py new file mode 100644 index 0000000..349c7ec --- /dev/null +++ b/core/apps/evaluation/translation/auto.py @@ -0,0 +1,8 @@ +from modeltranslation.translator import TranslationOptions, register + +from core.apps.evaluation.models import AutoEvaluationModel + + +@register(AutoEvaluationModel) +class AutoevaluationTranslation(TranslationOptions): + fields = [] diff --git a/core/apps/evaluation/urls.py b/core/apps/evaluation/urls.py index 1b74be8..b719882 100644 --- a/core/apps/evaluation/urls.py +++ b/core/apps/evaluation/urls.py @@ -1,9 +1,10 @@ from django.urls import include, path from rest_framework.routers import DefaultRouter -from .views import CustomerView, PropertyOwnerView, ValuationView, VehicleView +from .views import AutoEvaluationView, CustomerView, PropertyOwnerView, ValuationView, VehicleView router = DefaultRouter() +router.register("auto-evaluation", AutoEvaluationView, basename="auto-evaluation") router.register("Vehicle", VehicleView, basename="Vehicle") router.register("Valuation", ValuationView, basename="Valuation") router.register("property-owner", PropertyOwnerView, basename="property-owner") diff --git a/core/apps/evaluation/validators/__init__.py b/core/apps/evaluation/validators/__init__.py index 9683ac0..a21258a 100644 --- a/core/apps/evaluation/validators/__init__.py +++ b/core/apps/evaluation/validators/__init__.py @@ -1,3 +1,4 @@ +from .auto import * # noqa from .customer import * # noqa from .valuation import * # noqa from .vehicle import * # noqa diff --git a/core/apps/evaluation/validators/auto.py b/core/apps/evaluation/validators/auto.py new file mode 100644 index 0000000..e88c9e4 --- /dev/null +++ b/core/apps/evaluation/validators/auto.py @@ -0,0 +1,8 @@ +# from django.core.exceptions import ValidationError + + +class AutoevaluationValidator: + def __init__(self): ... + + def __call__(self): + return True diff --git a/core/apps/evaluation/views/__init__.py b/core/apps/evaluation/views/__init__.py index 9683ac0..a21258a 100644 --- a/core/apps/evaluation/views/__init__.py +++ b/core/apps/evaluation/views/__init__.py @@ -1,3 +1,4 @@ +from .auto import * # noqa from .customer import * # noqa from .valuation import * # noqa from .vehicle import * # noqa diff --git a/core/apps/evaluation/views/auto.py b/core/apps/evaluation/views/auto.py new file mode 100644 index 0000000..e49884d --- /dev/null +++ b/core/apps/evaluation/views/auto.py @@ -0,0 +1,25 @@ +from django_core.mixins import BaseViewSetMixin +from drf_spectacular.utils import extend_schema +from rest_framework.permissions import AllowAny +from rest_framework.viewsets import ReadOnlyModelViewSet + +from core.apps.evaluation.models import AutoEvaluationModel +from core.apps.evaluation.serializers.auto import ( + CreateAutoevaluationSerializer, + ListAutoevaluationSerializer, + RetrieveAutoevaluationSerializer, +) + + +@extend_schema(tags=["AutoEvaluation"]) +class AutoEvaluationView(BaseViewSetMixin, ReadOnlyModelViewSet): + queryset = AutoEvaluationModel.objects.all() + serializer_class = ListAutoevaluationSerializer + permission_classes = [AllowAny] + + action_permission_classes = {} + action_serializer_class = { + "list": ListAutoevaluationSerializer, + "retrieve": RetrieveAutoevaluationSerializer, + "create": CreateAutoevaluationSerializer, + }