Merge pull request 'AutoEvaluationModel qoshildi yani bu valuation bilan vehicle ni asosiy ulab beradigan model' (#10) from feat/evaluation-auto-model into main
All checks were successful
Deploy to Production / build-and-deploy (push) Successful in 3m11s
All checks were successful
Deploy to Production / build-and-deploy (push) Successful in 3m11s
Reviewed-on: #10
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .valuation import * # noqa
|
from .valuation import * # noqa
|
||||||
from .vehicle import * # noqa
|
from .vehicle import * # noqa
|
||||||
|
|||||||
12
core/apps/evaluation/admin/auto.py
Normal file
12
core/apps/evaluation/admin/auto.py
Normal file
@@ -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__",
|
||||||
|
)
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .valuation import * # noqa
|
from .valuation import * # noqa
|
||||||
from .vehicle import * # noqa
|
from .vehicle import * # noqa
|
||||||
|
|||||||
13
core/apps/evaluation/filters/auto.py
Normal file
13
core/apps/evaluation/filters/auto.py
Normal file
@@ -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",
|
||||||
|
# ]
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .valuation import * # noqa
|
from .valuation import * # noqa
|
||||||
from .vehicle import * # noqa
|
from .vehicle import * # noqa
|
||||||
|
|||||||
10
core/apps/evaluation/forms/auto.py
Normal file
10
core/apps/evaluation/forms/auto.py
Normal file
@@ -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__"
|
||||||
29
core/apps/evaluation/migrations/0004_autoevaluationmodel.py
Normal file
29
core/apps/evaluation/migrations/0004_autoevaluationmodel.py
Normal file
@@ -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',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .valuation import * # noqa
|
from .valuation import * # noqa
|
||||||
from .vehicle import * # noqa
|
from .vehicle import * # noqa
|
||||||
|
from .auto import * # noqa
|
||||||
|
|||||||
37
core/apps/evaluation/models/auto.py
Normal file
37
core/apps/evaluation/models/auto.py
Normal file
@@ -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")
|
||||||
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .valuation import * # noqa
|
from .valuation import * # noqa
|
||||||
from .vehicle import * # noqa
|
from .vehicle import * # noqa
|
||||||
|
|||||||
12
core/apps/evaluation/permissions/auto.py
Normal file
12
core/apps/evaluation/permissions/auto.py
Normal file
@@ -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
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .valuation import * # noqa
|
from .valuation import * # noqa
|
||||||
from .vehicle import * # noqa
|
from .vehicle import * # noqa
|
||||||
|
|||||||
28
core/apps/evaluation/serializers/auto/AutoEvaluation.py
Normal file
28
core/apps/evaluation/serializers/auto/AutoEvaluation.py
Normal file
@@ -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",
|
||||||
|
]
|
||||||
1
core/apps/evaluation/serializers/auto/__init__.py
Normal file
1
core/apps/evaluation/serializers/auto/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from .AutoEvaluation import * # noqa
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .valuation import * # noqa
|
from .valuation import * # noqa
|
||||||
from .vehicle import * # noqa
|
from .vehicle import * # noqa
|
||||||
|
|||||||
8
core/apps/evaluation/signals/auto.py
Normal file
8
core/apps/evaluation/signals/auto.py
Normal file
@@ -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): ...
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .valuation import * # noqa
|
from .valuation import * # noqa
|
||||||
from .vehicle import * # noqa
|
from .vehicle import * # noqa
|
||||||
|
|||||||
1
core/apps/evaluation/tests/auto/__init__.py
Normal file
1
core/apps/evaluation/tests/auto/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from .test_AutoEvaluation import * # noqa
|
||||||
101
core/apps/evaluation/tests/auto/test_AutoEvaluation.py
Normal file
101
core/apps/evaluation/tests/auto/test_AutoEvaluation.py
Normal file
@@ -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
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .valuation import * # noqa
|
from .valuation import * # noqa
|
||||||
from .vehicle import * # noqa
|
from .vehicle import * # noqa
|
||||||
|
|||||||
8
core/apps/evaluation/translation/auto.py
Normal file
8
core/apps/evaluation/translation/auto.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from modeltranslation.translator import TranslationOptions, register
|
||||||
|
|
||||||
|
from core.apps.evaluation.models import AutoEvaluationModel
|
||||||
|
|
||||||
|
|
||||||
|
@register(AutoEvaluationModel)
|
||||||
|
class AutoevaluationTranslation(TranslationOptions):
|
||||||
|
fields = []
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from rest_framework.routers import DefaultRouter
|
from rest_framework.routers import DefaultRouter
|
||||||
|
|
||||||
from .views import CustomerView, PropertyOwnerView, ValuationView, VehicleView
|
from .views import AutoEvaluationView, CustomerView, PropertyOwnerView, ValuationView, VehicleView
|
||||||
|
|
||||||
router = DefaultRouter()
|
router = DefaultRouter()
|
||||||
|
router.register("auto-evaluation", AutoEvaluationView, basename="auto-evaluation")
|
||||||
router.register("Vehicle", VehicleView, basename="Vehicle")
|
router.register("Vehicle", VehicleView, basename="Vehicle")
|
||||||
router.register("Valuation", ValuationView, basename="Valuation")
|
router.register("Valuation", ValuationView, basename="Valuation")
|
||||||
router.register("property-owner", PropertyOwnerView, basename="property-owner")
|
router.register("property-owner", PropertyOwnerView, basename="property-owner")
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .valuation import * # noqa
|
from .valuation import * # noqa
|
||||||
from .vehicle import * # noqa
|
from .vehicle import * # noqa
|
||||||
|
|||||||
8
core/apps/evaluation/validators/auto.py
Normal file
8
core/apps/evaluation/validators/auto.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
|
class AutoevaluationValidator:
|
||||||
|
def __init__(self): ...
|
||||||
|
|
||||||
|
def __call__(self):
|
||||||
|
return True
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from .auto import * # noqa
|
||||||
from .customer import * # noqa
|
from .customer import * # noqa
|
||||||
from .valuation import * # noqa
|
from .valuation import * # noqa
|
||||||
from .vehicle import * # noqa
|
from .vehicle import * # noqa
|
||||||
|
|||||||
25
core/apps/evaluation/views/auto.py
Normal file
25
core/apps/evaluation/views/auto.py
Normal file
@@ -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,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user