django-postgres-copy
django-postgres-copy copied to clipboard
Model-method transformation doesn't work after mapping
Maybe putting a little abstract of the code will explain better what is happening: file.csv
ColumnName
"144,54"
"435,12"
models.py
MyModel(models.Model):
my_attr_name = models.DecimalField(max_digits=10, decimal_places=2)
objects = CopyManager()
def copy_ColumnName_template(self):
return """
replace(%(name)s::text, ',', '.')::numeric * 1000
"""
management command
insert_count = MyModel.objects.from_csv(
csv_path,
mapping={"my_attr_name": "ColumnName"}
)
When I execute the command, I get a django.db.utils.DataError: invalid input syntax for type numeric: "144,54". It happens the same on any field typology, it's like the copy_ColumnName_template is skipped.
Am I missing something or using the transformation in a bad way? Without mapping, everything works as expected. Thanks