Features: 1) Add address_line field to Address model for enhanced customer address representation; 2) Extend serializers with address_line_1 and address_line_2 fields; 3) Update address parsing logic to include house number in street and support address_line storage;

Fixes: None;

Extra: Refactor address manager to construct `address_line` from parsed data;
This commit is contained in:
Egor Pavlovich Gorbunov 2025-05-28 22:07:06 +03:00
parent 09213dd616
commit 79c97b7e5a
4 changed files with 36 additions and 1 deletions

View file

@ -31,7 +31,7 @@ class AddressManager(models.Manager):
# Parse address components
addr = data.get("address", {})
street = addr.get("road") or addr.get("pedestrian") or ""
street = f"{addr.get('road', '') or addr.get('pedestrian', '')}, {addr.get('house_number', '')}"
district = addr.get("city_district") or addr.get("suburb") or ""
city = addr.get("city") or addr.get("town") or addr.get("village") or ""
region = addr.get("state") or addr.get("region") or ""
@ -49,6 +49,7 @@ class AddressManager(models.Manager):
# Create the model instance, storing both the input string and full API response
return super().create(
raw_data=raw_data,
address_line=f"{kwargs.get('address_line_1')}, {kwargs.get('address_line_2')}",
street=street,
district=district,
city=city,

View file

@ -0,0 +1,18 @@
# Generated by Django 5.2 on 2025-05-28 19:06
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0022_category_slug'),
]
operations = [
migrations.AddField(
model_name='address',
name='address_line',
field=models.TextField(blank=True, help_text='address line for the customer', null=True,
verbose_name='address line'),
),
]

View file

@ -1259,6 +1259,12 @@ class Documentary(NiceModel):
class Address(NiceModel):
is_publicly_visible = False
address_line = TextField( # noqa: DJ001
blank=True,
null=True,
help_text=_("address line for the customer"),
verbose_name=_("address line"),
)
street = CharField(_("street"), max_length=255, null=True) # noqa: DJ001
district = CharField(_("district"), max_length=255, null=True) # noqa: DJ001
city = CharField(_("city"), max_length=100, null=True) # noqa: DJ001

View file

@ -158,6 +158,16 @@ class AddressCreateSerializer(ModelSerializer): # noqa: F405
write_only=True,
max_length=512,
)
address_line_1 = CharField(
write_only=True,
max_length=128,
required=False
)
address_line_2 = CharField(
write_only=True,
max_length=128,
required=False
)
class Meta:
model = Address