I have a following model:
class Place(Base):
__tablename__ = 'places'
id: Mapped[BigIntPk]
name: Mapped['str'] = mapped_column(
String(128, collation=RU_RU_CE_COLLATION_NAME),
)
address: Mapped['str'] = mapped_column(
String(256, collation=RU_RU_CE_COLLATION_NAME),
)
region_name: Mapped[BigIntType] = mapped_column(
ForeignKey('regions.name', ondelete='RESTRICT', onupdate='CASCADE',),
)
coordinates = mapped_column(
Geography(geometry_type='POINT', nullable=True, spatial_index=False),
)
strikes: Mapped[list['Strike']] = relationship(
secondary='strike_to_place_associations',
passive_deletes=True,
back_populates='places',
)
region: Mapped['Region'] = relationship()
Thing is unlike with all other attributes whenever i need to set coordinates and sucessfully save model instance in database later i need to assign this exact attribute as :
from geoalchemy2 import WKTElement
coordinates = WKTElement(f'POINT({lat} {lon})')
instead of assigning coordinates in more usual format as tuple of lat, lon (22.8, 33.3) for example.
Question is - is it possible to assign coordinates attribute with bare tuple of (lat, lon) and then mutate it on assign or before save in database as it specified above?
I sort of found how to do it via events but it is quite hidenn away and implicit -> i dont like it this way....