add: add country model

This commit is contained in:
behruz-dev
2025-08-27 15:43:12 +05:00
parent de36e85d3d
commit 10c2eb86b4
8 changed files with 162 additions and 16 deletions

View File

@@ -0,0 +1,27 @@
# Generated by Django 5.2 on 2025-08-27 15:43
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('common', '0003_alter_service_options'),
]
operations = [
migrations.CreateModel(
name='Country',
fields=[
('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
('created_at', models.DateField(auto_now_add=True)),
('updated_at', models.DateField(auto_now=True)),
('name', models.CharField(max_length=200)),
],
options={
'verbose_name': 'Davlat',
'verbose_name_plural': 'Davlatlar',
},
),
]

View File

@@ -123,3 +123,14 @@ class SiteConfig(BaseModel):
class Meta:
verbose_name = 'sayt sozlamalari'
verbose_name_plural = 'sayt sozlamalari'
class Country(BaseModel):
name = models.CharField(max_length=200)
def __str__(self):
return self.name
class Meta:
verbose_name = 'Davlat'
verbose_name_plural = 'Davlatlar'

View File

@@ -43,4 +43,4 @@ class NewsListApiView(generics.ListAPIView):
class ContactUsApiView(generics.CreateAPIView):
serializer_class = serializers.ContactUsSerializer
queryset = models.ContactUs.objects.all()

View File

@@ -0,0 +1,55 @@
# Generated by Django 5.2 on 2025-08-27 15:43
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('common', '0004_country'),
('orders', '0003_order_order_number'),
]
operations = [
migrations.AddField(
model_name='order',
name='location_from',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='location_from', to='common.country'),
),
migrations.AddField(
model_name='order',
name='location_from_en',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='location_from', to='common.country'),
),
migrations.AddField(
model_name='order',
name='location_from_ru',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='location_from', to='common.country'),
),
migrations.AddField(
model_name='order',
name='location_from_uz',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='location_from', to='common.country'),
),
migrations.AddField(
model_name='order',
name='location_to',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='location_to', to='common.country'),
),
migrations.AddField(
model_name='order',
name='location_to_en',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='location_to', to='common.country'),
),
migrations.AddField(
model_name='order',
name='location_to_ru',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='location_to', to='common.country'),
),
migrations.AddField(
model_name='order',
name='location_to_uz',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='location_to', to='common.country'),
),
]

View File

@@ -2,6 +2,7 @@ from django.db import models
from core.apps.common.models import BaseModel
from core.apps.accounts.models import User
from core.apps.common.models import Country
class Order(BaseModel):
@@ -21,21 +22,12 @@ class Order(BaseModel):
total_price = models.PositiveBigIntegerField()
is_paid = models.BooleanField(default=False)
location = models.CharField(max_length=200)
location_to = models.CharField(max_length=200, null=True)
location_from = models.CharField(max_length=200, null=True)
location_to = models.ForeignKey(Country, on_delete=models.SET_NULL, null=True, related_name='location_to')
location_from = models.ForeignKey(Country, on_delete=models.SET_NULL, null=True, related_name='location_from')
def __str__(self):
return f'{self.user} user order {self.name}'
def save(self, *args, **kwargs):
if not self.order_number:
last_order = Order.objects.all().order_by('-order_number').first()
if last_order:
self.order_number = last_order.order_number + 1
else:
self.order_number = 1
super().save(*args, **kwargs)
class Meta:
verbose_name = 'Buyurtma'
verbose_name_plural = 'buyurtmalar'

View File

@@ -1,5 +1,5 @@
import hashlib
from django.conf import settings
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
@@ -7,7 +7,6 @@ from rest_framework import status
from core.apps.orders.models import Order
API_KEY = "ATMOS_API_KEY"
ALLOWED_ATMOS_IPS = ["185.8.212.47"]
def get_client_ip(request):
@@ -25,7 +24,7 @@ class AtmosCallbackApiView(APIView):
def post(self, request):
client_ip = get_client_ip(request)
if client_ip not in ALLOWED_ATMOS_IPS:
if client_ip not in settings.ALLOWED_ATMOS_IPS:
return Response({"status": 0, "message": "IP ruxsat etilmagan"}, status=403)
data = request.data
if not data: