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

Bulk create support #336

Merged
merged 2 commits into from Jan 15, 2018
Merged

Conversation

krzysztofgromadzki
Copy link
Contributor

Related issue: #204

This implementation just invokes pre_save_polymorphic method from PolymorphicModel for each saving object just before django's bulk_create . Usually this method is used in save method implementation in PolymorphicModel. Particullary pre_save_polymorphic method checks that foreign key to ContentType is set. If not, sets it.
Other possible solution (I didn't test it) is moving pre_save_polymorphic call to __init__ in PolymorphicModel and removed this call from save method. In this case overidded bulk_create won't exist

@vdboor vdboor merged commit 38a91a8 into jazzband:master Jan 15, 2018
@vdboor
Copy link
Collaborator

vdboor commented Jan 15, 2018

Cool! I think this is quite a nice solution! Django's bulk_create also performs a list(objs) so there is no performance issue here. While moving the pre_save_polymorphic logic to PolymorphicModel.__init__() could be possible, you'll have to be careful with overriding models. This solution avoids such traps! :-)

@ppolewicz ppolewicz deleted the bulk_create_support branch January 15, 2018 20:20
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

2 participants