feat(orders): add recipient management and enhance order forms

- Introduced Recipient model to manage order recipients separately from customers.
- Updated Order model to link to Recipient, replacing recipient_name and recipient_phone fields.
- Enhanced OrderForm to include recipient selection modes: customer, history, and new.
- Added AJAX endpoint to fetch recipient history for customers.
- Updated admin interface to manage recipients and display recipient information in order details.
- Refactored address handling to accommodate new recipient logic.
- Improved demo order creation to include random recipients.
This commit is contained in:
2025-12-23 00:08:41 +03:00
parent 483f150e7a
commit 6669d47cdf
15 changed files with 559 additions and 110 deletions

View File

@@ -0,0 +1,41 @@
from django.db import models
class Recipient(models.Model):
"""
Модель получателя заказа.
Один получатель может получать доставки по разным адресам.
"""
name = models.CharField(
max_length=200,
verbose_name="Имя получателя",
help_text="ФИО или название организации получателя"
)
phone = models.CharField(
max_length=20,
verbose_name="Телефон получателя",
help_text="Контактный телефон для связи с получателем"
)
# Временные метки
created_at = models.DateTimeField(auto_now_add=True, verbose_name="Дата создания")
updated_at = models.DateTimeField(auto_now=True, verbose_name="Дата обновления")
class Meta:
verbose_name = "Получатель"
verbose_name_plural = "Получатели"
indexes = [
models.Index(fields=['phone']),
models.Index(fields=['name']),
models.Index(fields=['created_at']),
]
ordering = ['-created_at']
def __str__(self):
return f"{self.name} ({self.phone})"
@property
def display_name(self):
"""Форматированное имя для отображения"""
return f"{self.name} - {self.phone}"