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

Updated Admin integration documentation to clarify how to save custom form values #1746

Conversation

matthewhegarty
Copy link
Contributor

Problem

Documentation was not clear on how to persist custom form selections.

Closes #1740

Solution

Updated the docs to clarify how to do this.

Acceptance Criteria

  • Tested documentation locally

@matthewhegarty matthewhegarty linked an issue Jan 27, 2024 that may be closed by this pull request
@matthewhegarty matthewhegarty merged commit f40c34a into django-import-export:release-4 Jan 27, 2024
13 checks passed
@matthewhegarty matthewhegarty deleted the issue-1740-custom-import-docs branch January 27, 2024 19:14
@eldavo
Copy link

eldavo commented Jan 29, 2024

@matthewhegarty I reviewed the docs and compared it with my implementation and am running into two issues. These may not be bugs per se with the documentation because my implementation uses a compound key with 4 attributes (You helped me on Stackoverflow with https://stackoverflow.com/questions/77085694/django-import-export-customize-admin-missing-field-error). Here are the two issues I'm running into:

  1. I must override after_import_instance in the corresponding resource , e.g.
 def after_import_instance(self, instance, new, row_number=None, **kwargs):
    instance.league = kwargs["league"]
    instance.season = kwargs["season"]
    pass

  1. I can import just fine, but when I try to do an update via CSV I receive the following error for all lines:
...
Line number: 1 - (1062, "Duplicate entry '3-2021' for key 'unique_team_season_key'")
...

However if I put columns and values in for league and season, updates work perfectly, so there's something going on with update and the customized admin if I am relying for form values to supply part of a compound key, either with documentation or my current implementation.

@matthewhegarty
Copy link
Contributor Author

Hi Dave

It looks like 1062 is coming from the DB itself i.e. clashing on a duplicate key. This means that import_export has not detected that your row is an update and is trying to create a new row. So something is wrong with the import logic in detecting existing rows. From what you say, presumably the 'league' and 'season' fields have to be present in order for the import process to detect that you have an existing entry.

The best thing to do is to step through with a debugger and see directly what the issue is. If it is a bug, please raise a new issue, or if you need any further help the best place to post is Stack Overflow.

@eldavo
Copy link

eldavo commented Jan 29, 2024

Thanks Matthew, will do.

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

Successfully merging this pull request may close these issues.

selected value of custom importForm is not being saved
2 participants