Добавил поле с именем

This commit is contained in:
zakhy 2025-03-04 10:06:02 +07:00
parent 4e7ef8198d
commit 3b7f01b551
6 changed files with 59 additions and 16 deletions

View File

@ -6,10 +6,5 @@ from apps.workerslocation.models.workers_locations import WorkersLocation
@admin.register(WorkersLocation)
class WorkersLocationAdmin(admin.ModelAdmin):
list_display = (
"abonent_id",
"latitude",
"longitude",
"velocity",
"radius",
"update_time",
"uid", "latitude", "longitude", "velocity", "radius", "update_time",
)

View File

@ -145,7 +145,7 @@ async def save_location(payload):
@sync_to_async
def create_or_update_location(data):
WorkersLocation.objects.update_or_create(
abonent_id=data["abonent_id"],
uid=data["abonent_id"],
defaults={
"latitude": data["latitude"],
"longitude": data["longitude"],

View File

@ -0,0 +1,30 @@
# Generated by Django 3.2.25 on 2025-03-04 02:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('workerslocation', '0006_alter_workerslocation_update_time'),
]
operations = [
migrations.AlterModelOptions(
name='workerslocation',
options={'ordering': ('uid',), 'verbose_name': 'объект', 'verbose_name_plural': 'объекты'},
),
migrations.RemoveIndex(
model_name='workerslocation',
name='workersloca_abonent_54a8c5_idx',
),
migrations.RenameField(
model_name='workerslocation',
old_name='abonent_id',
new_name='uid',
),
migrations.AddIndex(
model_name='workerslocation',
index=models.Index(fields=['uid'], name='workersloca_uid_cbf84d_idx'),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.25 on 2025-03-04 03:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('workerslocation', '0007_auto_20250304_0259'),
]
operations = [
migrations.AddField(
model_name='workerslocation',
name='name',
field=models.CharField(blank=True, max_length=128, null=True, verbose_name='Наименование'),
),
]

View File

@ -2,7 +2,8 @@ from django.db import models
class WorkersLocation(models.Model):
abonent_id = models.CharField(max_length=128, verbose_name="ID рации")
name = models.CharField(max_length=128, verbose_name="Наименование", blank=True, null=True)
uid = models.CharField(max_length=128, verbose_name="ID рации")
latitude = models.DecimalField(
default=0.0, max_digits=9, decimal_places=6, verbose_name="Широта"
)
@ -19,17 +20,17 @@ class WorkersLocation(models.Model):
active = models.BooleanField(default=True)
def __str__(self):
return self.abonent_id
return self.name if self.name else self.uid
class Meta: # отображение в админики
ordering = ("abonent_id",)
ordering = ("uid",)
verbose_name = "объект"
verbose_name_plural = "объекты"
indexes = [
models.Index(
fields=[
"abonent_id",
]
"uid",
],
),
models.Index(
fields=[

View File

@ -46,14 +46,13 @@ def update_object(request):
workers_mas.append(
{
"id": worker.id,
"name": worker.abonent_id,
"uid": worker.uid,
"name": worker.name if worker.name else worker.uid,
"lat": worker.latitude,
"lon": worker.longitude,
"velocity": worker.velocity,
"radius": worker.radius,
"time": worker.update_time.astimezone(
zoneinfo.ZoneInfo(settings.TIME_ZONE)
).strftime("%d.%m.%Y, %H:%M:%S"),
"time": worker.update_time.strftime("%d.%m.%Y, %H:%M:%S"),
}
)
return JsonResponse(workers_mas, safe=False)