Initial commit from monorepo
This commit is contained in:
0
suppliers/__init__.py
Normal file
0
suppliers/__init__.py
Normal file
10
suppliers/admin.py
Normal file
10
suppliers/admin.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.contrib import admin
|
||||
from .models import SupplierProfile
|
||||
|
||||
|
||||
@admin.register(SupplierProfile)
|
||||
class SupplierProfileAdmin(admin.ModelAdmin):
|
||||
list_display = ['name', 'country', 'is_verified', 'is_active', 'created_at']
|
||||
list_filter = ['is_verified', 'is_active', 'country']
|
||||
search_fields = ['name', 'description', 'team_uuid']
|
||||
readonly_fields = ['uuid', 'created_at', 'updated_at']
|
||||
7
suppliers/apps.py
Normal file
7
suppliers/apps.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SuppliersConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'suppliers'
|
||||
verbose_name = 'Профили поставщиков'
|
||||
0
suppliers/management/__init__.py
Normal file
0
suppliers/management/__init__.py
Normal file
0
suppliers/management/commands/__init__.py
Normal file
0
suppliers/management/commands/__init__.py
Normal file
34
suppliers/management/commands/fix_country_codes.py
Normal file
34
suppliers/management/commands/fix_country_codes.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db import transaction
|
||||
|
||||
from suppliers.models import SupplierProfile
|
||||
|
||||
|
||||
COUNTRY_TO_CODE = {
|
||||
"Russia": "RU",
|
||||
"Kazakhstan": "KZ",
|
||||
"Uzbekistan": "UZ",
|
||||
"Turkey": "TR",
|
||||
"UAE": "AE",
|
||||
"China": "CN",
|
||||
"India": "IN",
|
||||
"Germany": "DE",
|
||||
"Brazil": "BR",
|
||||
"Kenya": "KE",
|
||||
}
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Fill empty country_code based on country name"
|
||||
|
||||
@transaction.atomic
|
||||
def handle(self, *args, **options):
|
||||
updated = 0
|
||||
for profile in SupplierProfile.objects.filter(country_code=""):
|
||||
if profile.country in COUNTRY_TO_CODE:
|
||||
profile.country_code = COUNTRY_TO_CODE[profile.country]
|
||||
profile.save(update_fields=["country_code"])
|
||||
updated += 1
|
||||
self.stdout.write(f"Updated {profile.name}: {profile.country} -> {profile.country_code}")
|
||||
|
||||
self.stdout.write(self.style.SUCCESS(f"Updated {updated} supplier profiles"))
|
||||
32
suppliers/migrations/0001_initial.py
Normal file
32
suppliers/migrations/0001_initial.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Supplier',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('uuid', models.CharField(default=uuid.uuid4, max_length=100, unique=True)),
|
||||
('team_uuid', models.CharField(max_length=100, unique=True)),
|
||||
('name', models.CharField(max_length=255)),
|
||||
('description', models.TextField(blank=True, default='')),
|
||||
('country', models.CharField(blank=True, default='', max_length=100)),
|
||||
('logo_url', models.URLField(blank=True, default='')),
|
||||
('is_verified', models.BooleanField(default=False)),
|
||||
('is_active', models.BooleanField(default=True)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'suppliers',
|
||||
'ordering': ['name'],
|
||||
},
|
||||
),
|
||||
]
|
||||
18
suppliers/migrations/0002_supplier_country_code.py
Normal file
18
suppliers/migrations/0002_supplier_country_code.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.9 on 2025-12-10 05:20
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('suppliers', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='supplier',
|
||||
name='country_code',
|
||||
field=models.CharField(blank=True, default='', max_length=3),
|
||||
),
|
||||
]
|
||||
23
suppliers/migrations/0003_add_coordinates.py
Normal file
23
suppliers/migrations/0003_add_coordinates.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.2.9 on 2025-12-10 11:56
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('suppliers', '0002_supplier_country_code'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='supplier',
|
||||
name='latitude',
|
||||
field=models.FloatField(blank=True, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='supplier',
|
||||
name='longitude',
|
||||
field=models.FloatField(blank=True, null=True),
|
||||
),
|
||||
]
|
||||
1
suppliers/migrations/__init__.py
Normal file
1
suppliers/migrations/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
41
suppliers/models.py
Normal file
41
suppliers/models.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from django.db import models
|
||||
import uuid
|
||||
|
||||
|
||||
class SupplierProfile(models.Model):
|
||||
"""Профиль поставщика на бирже - витринные данные для marketplace.
|
||||
|
||||
Первоисточник данных о поставщике - Team (team_type=SELLER).
|
||||
Этот профиль содержит только витринную информацию для отображения на бирже.
|
||||
"""
|
||||
uuid = models.CharField(max_length=100, unique=True, default=uuid.uuid4)
|
||||
team_uuid = models.CharField(max_length=100, unique=True) # Связь с Team
|
||||
|
||||
name = models.CharField(max_length=255)
|
||||
description = models.TextField(blank=True, default='')
|
||||
country = models.CharField(max_length=100, blank=True, default='')
|
||||
country_code = models.CharField(max_length=3, blank=True, default='')
|
||||
logo_url = models.URLField(blank=True, default='')
|
||||
|
||||
# Координаты для карты
|
||||
latitude = models.FloatField(null=True, blank=True)
|
||||
longitude = models.FloatField(null=True, blank=True)
|
||||
|
||||
is_verified = models.BooleanField(default=False)
|
||||
is_active = models.BooleanField(default=True)
|
||||
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
db_table = 'suppliers' # Сохраняем имя таблицы для совместимости
|
||||
ordering = ['name']
|
||||
verbose_name = 'Supplier Profile'
|
||||
verbose_name_plural = 'Supplier Profiles'
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} ({self.country})"
|
||||
|
||||
|
||||
# Alias for backwards compatibility
|
||||
Supplier = SupplierProfile
|
||||
Reference in New Issue
Block a user