Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty Identifiers for nullable ForeignKeyFields #44

Open
SchrodingersGat opened this issue Mar 21, 2024 · 1 comment
Open

Empty Identifiers for nullable ForeignKeyFields #44

SchrodingersGat opened this issue Mar 21, 2024 · 1 comment

Comments

@SchrodingersGat
Copy link

SchrodingersGat commented Mar 21, 2024

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.

@sheppard
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants