Merge pull request 'RealEstateEvaluationModel modeli qoshildi (Ko'chmas mulk (Real Estate) baholash modeli uchun quyidagicha nomlarni tavsiya qilaman:' (#11) from feat/evaluation-real-estate-models into main
All checks were successful
Deploy to Production / build-and-deploy (push) Successful in 3m4s
All checks were successful
Deploy to Production / build-and-deploy (push) Successful in 3m4s
Reviewed-on: #11
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
12
core/apps/evaluation/admin/real_estate.py
Normal file
12
core/apps/evaluation/admin/real_estate.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from django.contrib import admin
|
||||
from unfold.admin import ModelAdmin
|
||||
|
||||
from core.apps.evaluation.models import RealEstateEvaluationModel
|
||||
|
||||
|
||||
@admin.register(RealEstateEvaluationModel)
|
||||
class RealestateevaluationAdmin(ModelAdmin):
|
||||
list_display = (
|
||||
"id",
|
||||
"__str__",
|
||||
)
|
||||
18
core/apps/evaluation/choices/real_estate.py
Normal file
18
core/apps/evaluation/choices/real_estate.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class PropertyType(models.TextChoices):
|
||||
APARTMENT = "apartment", _("Apartment")
|
||||
HOUSE = "house", _("House")
|
||||
OFFICE = "office", _("Office")
|
||||
LAND = "land", _("Land")
|
||||
COMMERCIAL = "commercial", _("Commercial")
|
||||
INDUSTRIAL = "industrial", _("Industrial")
|
||||
|
||||
|
||||
class RealEstateCondition(models.TextChoices):
|
||||
NEW = "new", _("New (Rough finish)")
|
||||
FINISHED = "finished", _("Finished (Standard/Euro)")
|
||||
REPAIR_REQUIRED = "repair_required", _("Needs repair")
|
||||
UNDER_CONSTRUCTION = "under_construction", _("Under construction")
|
||||
@@ -1,4 +1,5 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
13
core/apps/evaluation/filters/real_estate.py
Normal file
13
core/apps/evaluation/filters/real_estate.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from django_filters import rest_framework as filters
|
||||
|
||||
from core.apps.evaluation.models import RealEstateEvaluationModel
|
||||
|
||||
|
||||
class RealestateevaluationFilter(filters.FilterSet):
|
||||
# name = filters.CharFilter(field_name="name", lookup_expr="icontains")
|
||||
|
||||
class Meta:
|
||||
model = RealEstateEvaluationModel
|
||||
fields = [
|
||||
"name",
|
||||
]
|
||||
@@ -1,4 +1,5 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
10
core/apps/evaluation/forms/real_estate.py
Normal file
10
core/apps/evaluation/forms/real_estate.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django import forms
|
||||
|
||||
from core.apps.evaluation.models import RealEstateEvaluationModel
|
||||
|
||||
|
||||
class RealestateevaluationForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = RealEstateEvaluationModel
|
||||
fields = "__all__"
|
||||
@@ -0,0 +1,39 @@
|
||||
# Generated by Django 5.2.7 on 2026-02-13 12:30
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('evaluation', '0004_autoevaluationmodel'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='RealEstateEvaluationModel',
|
||||
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)),
|
||||
('property_type', models.CharField(choices=[('apartment', 'Apartment'), ('house', 'House'), ('office', 'Office'), ('land', 'Land'), ('commercial', 'Commercial'), ('industrial', 'Industrial')], default='apartment', max_length=50, verbose_name='property type')),
|
||||
('address', models.TextField(verbose_name='address')),
|
||||
('cadastral_number', models.CharField(blank=True, max_length=50, null=True, verbose_name='cadastral number')),
|
||||
('total_area', models.DecimalField(decimal_places=2, max_digits=12, verbose_name='total area')),
|
||||
('living_area', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True, verbose_name='living area')),
|
||||
('floor', models.IntegerField(blank=True, null=True, verbose_name='floor')),
|
||||
('total_floors', models.IntegerField(blank=True, null=True, verbose_name='total floors')),
|
||||
('rooms_count', models.IntegerField(blank=True, null=True, verbose_name='rooms count')),
|
||||
('build_year', models.IntegerField(blank=True, null=True, verbose_name='build year')),
|
||||
('condition', models.CharField(blank=True, choices=[('new', 'New (Rough finish)'), ('finished', 'Finished (Standard/Euro)'), ('repair_required', 'Needs repair'), ('under_construction', 'Under construction')], max_length=50, null=True, verbose_name='condition')),
|
||||
('has_renovation', models.BooleanField(default=False, verbose_name='has renovation')),
|
||||
('valuation', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='real_estate_detail', to='evaluation.valuationmodel', verbose_name='valuation')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Real Estate Evaluation',
|
||||
'verbose_name_plural': 'Real Estate Evaluations',
|
||||
'db_table': 'RealEstateEvaluation',
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -1,5 +1,7 @@
|
||||
from .auto import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
|
||||
from .customer import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
from .auto import * # noqa
|
||||
|
||||
68
core/apps/evaluation/models/real_estate.py
Normal file
68
core/apps/evaluation/models/real_estate.py
Normal file
@@ -0,0 +1,68 @@
|
||||
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 core.apps.evaluation.choices.real_estate import PropertyType, RealEstateCondition
|
||||
|
||||
|
||||
|
||||
|
||||
class RealEstateEvaluationModel(AbstractBaseModel):
|
||||
valuation = models.OneToOneField(
|
||||
ValuationModel,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="real_estate_detail",
|
||||
verbose_name=_("valuation"),
|
||||
)
|
||||
property_type = models.CharField(
|
||||
verbose_name=_("property type"),
|
||||
max_length=50,
|
||||
choices=PropertyType.choices,
|
||||
default=PropertyType.APARTMENT,
|
||||
)
|
||||
address = models.TextField(verbose_name=_("address"))
|
||||
cadastral_number = models.CharField(
|
||||
verbose_name=_("cadastral number"), max_length=50, blank=True, null=True
|
||||
)
|
||||
total_area = models.DecimalField(
|
||||
verbose_name=_("total area"), max_digits=12, decimal_places=2
|
||||
)
|
||||
living_area = models.DecimalField(
|
||||
verbose_name=_("living area"),
|
||||
max_digits=12,
|
||||
decimal_places=2,
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
floor = models.IntegerField(verbose_name=_("floor"), blank=True, null=True)
|
||||
total_floors = models.IntegerField(
|
||||
verbose_name=_("total floors"), blank=True, null=True
|
||||
)
|
||||
rooms_count = models.IntegerField(
|
||||
verbose_name=_("rooms count"), blank=True, null=True
|
||||
)
|
||||
build_year = models.IntegerField(verbose_name=_("build year"), blank=True, null=True)
|
||||
condition = models.CharField(
|
||||
verbose_name=_("condition"),
|
||||
max_length=50,
|
||||
choices=RealEstateCondition.choices,
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
has_renovation = models.BooleanField(verbose_name=_("has renovation"), default=False)
|
||||
|
||||
def __str__(self):
|
||||
return f"Real Estate Evaluation for {self.valuation}"
|
||||
|
||||
@classmethod
|
||||
def _baker(cls):
|
||||
return baker.make(cls)
|
||||
|
||||
class Meta:
|
||||
db_table = "RealEstateEvaluation"
|
||||
verbose_name = _("Real Estate Evaluation")
|
||||
verbose_name_plural = _("Real Estate Evaluations")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
12
core/apps/evaluation/permissions/real_estate.py
Normal file
12
core/apps/evaluation/permissions/real_estate.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from rest_framework import permissions
|
||||
|
||||
|
||||
class RealestateevaluationPermission(permissions.BasePermission):
|
||||
|
||||
def __init__(self) -> None: ...
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return True
|
||||
@@ -1,4 +1,5 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
@@ -9,6 +9,7 @@ class BaseAutoevaluationSerializer(serializers.ModelSerializer):
|
||||
fields = [
|
||||
"id",
|
||||
"valuation",
|
||||
"vehicle",
|
||||
]
|
||||
|
||||
|
||||
@@ -25,4 +26,5 @@ class CreateAutoevaluationSerializer(BaseAutoevaluationSerializer):
|
||||
fields = [
|
||||
"id",
|
||||
"valuation",
|
||||
"vehicle",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from core.apps.evaluation.models import RealEstateEvaluationModel
|
||||
|
||||
|
||||
class BaseRealestateevaluationSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = RealEstateEvaluationModel
|
||||
fields = [
|
||||
"id",
|
||||
"valuation",
|
||||
"property_type",
|
||||
"address",
|
||||
"cadastral_number",
|
||||
"total_area",
|
||||
"living_area",
|
||||
"floor",
|
||||
"total_floors",
|
||||
"rooms_count",
|
||||
"build_year",
|
||||
"condition",
|
||||
"has_renovation",
|
||||
]
|
||||
|
||||
|
||||
class ListRealestateevaluationSerializer(BaseRealestateevaluationSerializer):
|
||||
class Meta(BaseRealestateevaluationSerializer.Meta): ...
|
||||
|
||||
|
||||
class RetrieveRealestateevaluationSerializer(BaseRealestateevaluationSerializer):
|
||||
class Meta(BaseRealestateevaluationSerializer.Meta): ...
|
||||
|
||||
|
||||
class CreateRealestateevaluationSerializer(BaseRealestateevaluationSerializer):
|
||||
class Meta(BaseRealestateevaluationSerializer.Meta):
|
||||
fields = [
|
||||
"id",
|
||||
"valuation",
|
||||
"property_type",
|
||||
"address",
|
||||
"cadastral_number",
|
||||
"total_area",
|
||||
"living_area",
|
||||
"floor",
|
||||
"total_floors",
|
||||
"rooms_count",
|
||||
"build_year",
|
||||
"condition",
|
||||
"has_renovation",
|
||||
]
|
||||
1
core/apps/evaluation/serializers/real_estate/__init__.py
Normal file
1
core/apps/evaluation/serializers/real_estate/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .RealEstateEvaluation import * # noqa
|
||||
@@ -1,4 +1,5 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
8
core/apps/evaluation/signals/real_estate.py
Normal file
8
core/apps/evaluation/signals/real_estate.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 RealEstateEvaluationModel
|
||||
|
||||
|
||||
@receiver(post_save, sender=RealEstateEvaluationModel)
|
||||
def RealestateevaluationSignal(sender, instance, created, **kwargs): ...
|
||||
@@ -1,4 +1,5 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
1
core/apps/evaluation/tests/real_estate/__init__.py
Normal file
1
core/apps/evaluation/tests/real_estate/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .test_RealEstateEvaluation import * # noqa
|
||||
@@ -0,0 +1,101 @@
|
||||
import pytest
|
||||
from django.urls import reverse
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from core.apps.evaluation.models import RealEstateEvaluationModel
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def instance(db):
|
||||
return RealEstateEvaluationModel._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("real-estate-evaluation-list"),
|
||||
"retrieve": reverse("real-estate-evaluation-detail", kwargs={"pk": instance.pk}),
|
||||
"retrieve-not-found": reverse("real-estate-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
|
||||
@@ -22,9 +22,9 @@ def data(api_client):
|
||||
client, instance = api_client
|
||||
return (
|
||||
{
|
||||
"list": reverse("Valuation-list"),
|
||||
"retrieve": reverse("Valuation-detail", kwargs={"pk": instance.pk}),
|
||||
"retrieve-not-found": reverse("Valuation-detail", kwargs={"pk": 1000}),
|
||||
"list": reverse("valuation-list"),
|
||||
"retrieve": reverse("valuation-detail", kwargs={"pk": instance.pk}),
|
||||
"retrieve-not-found": reverse("valuation-detail", kwargs={"pk": 1000}),
|
||||
},
|
||||
client,
|
||||
instance,
|
||||
|
||||
@@ -22,9 +22,9 @@ def data(api_client):
|
||||
client, instance = api_client
|
||||
return (
|
||||
{
|
||||
"list": reverse("Vehicle-list"),
|
||||
"retrieve": reverse("Vehicle-detail", kwargs={"pk": instance.pk}),
|
||||
"retrieve-not-found": reverse("Vehicle-detail", kwargs={"pk": 1000}),
|
||||
"list": reverse("vehicle-list"),
|
||||
"retrieve": reverse("vehicle-detail", kwargs={"pk": instance.pk}),
|
||||
"retrieve-not-found": reverse("vehicle-detail", kwargs={"pk": 1000}),
|
||||
},
|
||||
client,
|
||||
instance,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
8
core/apps/evaluation/translation/real_estate.py
Normal file
8
core/apps/evaluation/translation/real_estate.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from modeltranslation.translator import TranslationOptions, register
|
||||
|
||||
from core.apps.evaluation.models import RealEstateEvaluationModel
|
||||
|
||||
|
||||
@register(RealEstateEvaluationModel)
|
||||
class RealestateevaluationTranslation(TranslationOptions):
|
||||
fields = []
|
||||
@@ -1,12 +1,20 @@
|
||||
from django.urls import include, path
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from .views import AutoEvaluationView, CustomerView, PropertyOwnerView, ValuationView, VehicleView
|
||||
from .views import (
|
||||
AutoEvaluationView,
|
||||
CustomerView,
|
||||
PropertyOwnerView,
|
||||
RealEstateEvaluationView,
|
||||
ValuationView,
|
||||
VehicleView,
|
||||
)
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register("real-estate-evaluation", RealEstateEvaluationView, basename="real-estate-evaluation")
|
||||
router.register("auto-evaluation", AutoEvaluationView, basename="auto-evaluation")
|
||||
router.register("Vehicle", VehicleView, basename="Vehicle")
|
||||
router.register("Valuation", ValuationView, basename="Valuation")
|
||||
router.register("vehicle", VehicleView, basename="vehicle")
|
||||
router.register("valuation", ValuationView, basename="valuation")
|
||||
router.register("property-owner", PropertyOwnerView, basename="property-owner")
|
||||
router.register("customer", CustomerView, basename="customer")
|
||||
urlpatterns = [path("", include(router.urls))]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
8
core/apps/evaluation/validators/real_estate.py
Normal file
8
core/apps/evaluation/validators/real_estate.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# from django.core.exceptions import ValidationError
|
||||
|
||||
|
||||
class RealestateevaluationValidator:
|
||||
def __init__(self): ...
|
||||
|
||||
def __call__(self):
|
||||
return True
|
||||
@@ -1,4 +1,5 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
25
core/apps/evaluation/views/real_estate.py
Normal file
25
core/apps/evaluation/views/real_estate.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 RealEstateEvaluationModel
|
||||
from core.apps.evaluation.serializers.real_estate import (
|
||||
CreateRealestateevaluationSerializer,
|
||||
ListRealestateevaluationSerializer,
|
||||
RetrieveRealestateevaluationSerializer,
|
||||
)
|
||||
|
||||
|
||||
@extend_schema(tags=["RealEstateEvaluation"])
|
||||
class RealEstateEvaluationView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
||||
queryset = RealEstateEvaluationModel.objects.all()
|
||||
serializer_class = ListRealestateevaluationSerializer
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
action_permission_classes = {}
|
||||
action_serializer_class = {
|
||||
"list": ListRealestateevaluationSerializer,
|
||||
"retrieve": RetrieveRealestateevaluationSerializer,
|
||||
"create": CreateRealestateevaluationSerializer,
|
||||
}
|
||||
Reference in New Issue
Block a user