From 8c286aa2f0047d557085d363aa1abd8743c44dfc Mon Sep 17 00:00:00 2001 From: AlexP077 Date: Mon, 13 Mar 2023 21:11:27 +0300 Subject: [PATCH] fix2 --- service/admin.py | 2 -- .../0013_alter_placementpoint_status.py | 18 ++++++++++++++++++ .../0014_alter_placementpoint_postamat_id.py | 18 ++++++++++++++++++ service/models.py | 10 +++++----- service/utils.py | 7 +++---- 5 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 service/migrations/0013_alter_placementpoint_status.py create mode 100644 service/migrations/0014_alter_placementpoint_postamat_id.py diff --git a/service/admin.py b/service/admin.py index 4202628..a998658 100644 --- a/service/admin.py +++ b/service/admin.py @@ -1,6 +1,5 @@ from django.contrib import admin -from service.models import PlacementPoint, AO, Rayon from service.models import AO from service.models import PlacementPoint from service.models import PointDist @@ -13,7 +12,6 @@ admin.site.register(Rivals) admin.site.register(PointDist) - class PlacementPointAdmin(admin.ModelAdmin): pass diff --git a/service/migrations/0013_alter_placementpoint_status.py b/service/migrations/0013_alter_placementpoint_status.py new file mode 100644 index 0000000..87d7e68 --- /dev/null +++ b/service/migrations/0013_alter_placementpoint_status.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2 on 2023-03-13 17:59 +from django.db import migrations +from django.db import models + + +class Migration(migrations.Migration): + + dependencies = [ + ('service', '0012_auto_20230313_1951'), + ] + + operations = [ + migrations.AlterField( + model_name='placementpoint', + name='status', + field=models.TextField(blank=True, choices=[('Pending', 'К рассмотрению'), ('Installation', 'Согласование-Установка'), ('Working', 'Работает'), ('Cancelled', 'Отменено')], null=True, verbose_name='Статус'), + ), + ] diff --git a/service/migrations/0014_alter_placementpoint_postamat_id.py b/service/migrations/0014_alter_placementpoint_postamat_id.py new file mode 100644 index 0000000..89d5d01 --- /dev/null +++ b/service/migrations/0014_alter_placementpoint_postamat_id.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2 on 2023-03-13 18:02 +from django.db import migrations +from django.db import models + + +class Migration(migrations.Migration): + + dependencies = [ + ('service', '0013_alter_placementpoint_status'), + ] + + operations = [ + migrations.AlterField( + model_name='placementpoint', + name='postamat_id', + field=models.TextField(blank=True, null=True, unique=True, verbose_name='ID постамата'), + ), + ] diff --git a/service/models.py b/service/models.py index 3158e37..e7dcc62 100644 --- a/service/models.py +++ b/service/models.py @@ -6,14 +6,14 @@ from service.signals import * class PlacementPoint(models.Model): STATUS_CHOICES = ( - ('К рассмотрению', 'К рассмотрению'), - ('Согласование-Установка', 'Согласование-Установка'), - ('Работает', 'Работает'), - ('Отменено', 'Отменено'), + ('Pending', 'К рассмотрению'), + ('Installation', 'Согласование-Установка'), + ('Working', 'Работает'), + ('Cancelled', 'Отменено'), ) address = models.TextField(null=True, blank=True, verbose_name='Адрес') name = models.TextField(null=True, blank=True, verbose_name='Название') - postamat_id = models.TextField(null=True, blank=True, verbose_name='ID постамата') + postamat_id = models.TextField(unique=True, null=True, blank=True, verbose_name='ID постамата') category = models.TextField(null=True, blank=True, verbose_name='Категория') status = models.TextField(choices=STATUS_CHOICES, null=True, blank=True, verbose_name='Статус') start_date = models.DateTimeField(null=True, blank=True) diff --git a/service/utils.py b/service/utils.py index ca5ab63..4769d4b 100644 --- a/service/utils.py +++ b/service/utils.py @@ -14,16 +14,15 @@ def load_data(filepath: str): df = df.replace(np.nan, None) df = df.replace('NaT', None) for row in tqdm(df.to_dict('records'), desc='Loading data...'): - data = {k: row[k] for k in row.keys() if k not in ['id', 'okrug', 'rayon', 'age_month']} - data['location_id'] = row['id'] + data = {k: row[k] for k in row.keys() if k not in ['id', 'location_id', 'okrug', 'rayon', 'age_month']} data['okrug'] = models.AO.objects.get(name=row['okrug']) data['rayon'] = models.Rayon.objects.get(name=row['rayon']) models.PlacementPoint.objects.create(**data) def load_ao_and_rayons( - ao_filepath: str, - rayons_filepath: str, + ao_filepath: str, + rayons_filepath: str, ): models.AO.objects.all().delete() models.Rayon.objects.all().delete()