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

Fixes #1544. Add new parameter to Field called m2m_add which changes… #1545

Merged
merged 6 commits into from Feb 21, 2023
Merged

Fixes #1544. Add new parameter to Field called m2m_add which changes… #1545

merged 6 commits into from Feb 21, 2023

Conversation

bdnettleton
Copy link
Contributor

Add new parameter to Field called m2m_add which changes the behavior of Field.save such that it calls "add" instead of "set" for m2m fields.

Problem

Enables creating a resource which adds values to a ManyToMany field instead of overwriting existing values.

Solution

When m2m_add is True call the add method instead of the set method on an m2m field. Exclude already existing values in the m2m field so that multiple exports and re-imports don't keep adding the same fields repeatedly.

Acceptance Criteria

Have you written tests? Yes

Have you included screenshots of your changes if applicable? N/A

Did you document your changes? Yes. Added documentation in the docstring for the new m2m_add parameter.

…the behavior of Field.save such that it calls "add" instead of "set" for m2m fields.
@bdnettleton
Copy link
Contributor Author

Fixed test_fields.py to not use new python feature mock.Mock.call_args.args (which wasn't supported in python 3.7). Python 3.7 isn't supported on my computer (Apple M1 Mac) so wasn't able to test python 3.7 without running on GitHub.

Copy link
Contributor

@matthewhegarty matthewhegarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting Brian.
I think it looks ok - I have a comment about the use of all() as this would have a performance impact and may not be required.

import_export/fields.py Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Feb 16, 2023

Coverage Status

Coverage: 100.0%. Remained the same when pulling 315576f on bdnettleton:resolve-conflicts-pr-1545 into 7cd6cdc on django-import-export:main.

@bdnettleton
Copy link
Contributor Author

Removed the call to .all() as you recommended. It is unnecessary. Thanks!

@matthewhegarty
Copy link
Contributor

Thanks - free free to add your name to AUTHORS and I will merge.

@bdnettleton
Copy link
Contributor Author

Done, with update for AUTHORS. Hit a conflict with AUTHORS which I think I've got resolved now.

@matthewhegarty matthewhegarty merged commit c6eb440 into django-import-export:main Feb 21, 2023
@bdnettleton bdnettleton deleted the resolve-conflicts-pr-1545 branch February 21, 2023 18:51
@bdnettleton
Copy link
Contributor Author

Thanks Matt!

@matthewhegarty
Copy link
Contributor

Thank you 👍 Now released in v3.1.0

@bdnettleton
Copy link
Contributor Author

bdnettleton commented Feb 21, 2023 via email

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.

None yet

3 participants