wq/django-data-wizard

Automatically mapping the FK rows

shashitechno opened this issue · 3 comments

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.

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:

ident = Identifier.objects.create(
serializer=run.serializer,
field=field_name,
name=name,
)

Columns are already pre-mapped if they exactly match the serializer names). See this line:

if name in get_choice_ids(run):
field = name
else:
field = None
ident = Identifier.objects.create(
serializer=run.serializer,
name=name,
field=field,
resolved=(field is not None),
)

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

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

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

  • "data_wizard.idmap.never": Require user to manually map all IDs the first time (current default)
  • "data_wizard.idmap.existing": Automatically map existing IDs, but require user to map unknown ids (future default)
  • "data_wizard.idmap.always": Always map IDs (skip manual mapping). Unknown IDs will be passed on as-is to the serializer, which will cause per-row errors (unless using natural keys).