django-data-wizard icon indicating copy to clipboard operation
django-data-wizard copied to clipboard

Empty Identifiers for nullable ForeignKeyFields

Open SchrodingersGat opened this issue 1 year ago • 1 comments

Maybe I am missing something obvious here, but there does not seem to be a way to import data which contains "empty" foreign key references to a nullable foreign key field?

Here is a screenshot of what I am talking about:

image

Here the foreign key is to a "part category". An "empty" value in the identifier cannot be mapped to a "null" or "ignore" value. It appears that I am forced to select from an existing "category" - even though the model field in question is nullable.

SchrodingersGat avatar Mar 21 '24 12:03 SchrodingersGat

This is missing from the current implementation, but it would definitely make sense to add it. The "Ignore this Column" option works by letting the user set the identifier value to "__ignore__", relying on the fact that there is no serializer field with that name. To do the same thing for foreign keys, we could allow the user to map the value to "__null__" and then update data_wizard.tasks.build_row() to replace that with None:

if ident and ident.value:
    if ident.value == "__null__":
        record[field_name] = None
    else:
        record[field_name] = ident.value

sheppard avatar Mar 22 '24 14:03 sheppard