ambitioninc / django-query-builder

Build complex queries for Django
django-query-builder.readthedocs.org
MIT License
176 stars 33 forks source link

Support for upserting models with fields containing custom db_column #86

Closed sathoro closed 7 years ago

sathoro commented 7 years ago

Currently if you have a field where you specify a db_column and try to upsert it will throw an AttributeError. This change fixes that by using the field's attname instead of column to get the value.

The only case this this would break backwards compatibility that I can think of is if a model has a property defined on it with the same name as the attname but I think that this is the more sane default in that situation as well.

somewes commented 7 years ago

Hey @sathoro thanks for contributing! I'll work on adding in your changes for the next release.

sathoro commented 7 years ago

@wesokes Great! By the way, is there interest in supporting passing in a list of dicts instead of model objects to upsert? I patched the code to allow that because I found there is a substantial performance difference when dealing with a large number of objects.

somewes commented 7 years ago

@sathoro definitely interested in the list of dicts! we have been working on optimizing the speed of another project and noticed the huge improvement when avoiding models.

sathoro commented 7 years ago

@wesokes Cool I also made a change so that it will optionally return a boolean for each row indicating whether it was inserted (as opposed to updated) so I can include that as well.

somewes commented 7 years ago

@sathoro i included these suggested changes in https://github.com/ambitioninc/django-query-builder/pull/88 and added a little bit more to the test. the next release will be 0.15.0 which includes django support up to 1.11 (and fixed the 2.0 warnings) as well as python 3.6.