wq / django-data-wizard

🧙⚙️ Import structured data (e.g. Excel, CSV, XML, JSON) into one or more Django models via an interactive web-based wizard
https://django-data-wizard.wq.io
MIT License
338 stars 53 forks source link

Automatically mapping the FK rows #14

Closed shashitechno closed 4 years ago

shashitechno commented 5 years ago

Hey guys,

A question I have a CSV with first column as FK ID - and whenever I do a POST to "auto" endpoint - it stucks saying "input needed" on IDs

I am pretty sure, I am missing something - someone please direct me?

Thanks in Advance

Table A - name, title

Table B - FK_A, place, price

importing CSV for table B where FK_A is the foreign key to table A records.

sheppard commented 5 years ago

Yes, currently identifiers always need to be mapped even if they exactly match existing primary keys. This should only need to happen once and then future imports should just work (at least for the same fks). If you expect your CSV to always have valid ids, you can try using the data task instead of the auto task.

To make this work for the auto task, PRs are always welcome. The fix would probably be to pre-assign the "value" for recognized identifiers in these lines: https://github.com/wq/django-data-wizard/blob/2863c98c1b8a17a9fa688aed5c08ea2ecefafdb4/data_wizard/tasks.py#L562-L566

Columns are already pre-mapped if they exactly match the serializer names). See this line: https://github.com/wq/django-data-wizard/blob/2863c98c1b8a17a9fa688aed5c08ea2ecefafdb4/data_wizard/tasks.py#L433-L442

The new admin interface (#6) should help clarify how the Identifier model is used.

shashitechno commented 5 years ago

Thanks @sheppard, I ended up mapping them manually - although the FK relations can be mapped via assign field as value

django-data-wizard/data_wizard/tasks.py Lines 433 to 442 in 2863c98

sheppard commented 4 years ago

This is now configurable through the new DATA_WIZARD['IDMAP'] setting.