diff options
| author | Alex Gaynor <alex.gaynor@gmail.com> | 2011-09-09 19:22:28 +0000 |
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@gmail.com> | 2011-09-09 19:22:28 +0000 |
| commit | 7deb25b8dd5aa1ed02b5e30cbc67cd1fb0c3d6e6 (patch) | |
| tree | 09ed3208f309d71b5710b8287bccdb92ddf40c58 /django/utils | |
| parent | e55bbf4c3c42b17d52c21bc3a460b4981fdc190c (diff) | |
Fixed #7596. Added Model.objects.bulk_create, and make use of it in several places. This provides a performance benefit when inserting multiple objects. THanks to Russ for the review, and Simon Meers for the MySQl implementation.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16739 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/functional.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/django/utils/functional.py b/django/utils/functional.py index c8f8ee33c7..1345d3b005 100644 --- a/django/utils/functional.py +++ b/django/utils/functional.py @@ -275,4 +275,17 @@ class lazy_property(property): @wraps(fdel) def fdel(instance, name=fdel.__name__): return getattr(instance, name)() - return property(fget, fset, fdel, doc)
\ No newline at end of file + return property(fget, fset, fdel, doc) + +def partition(predicate, values): + """ + Splits the values into two sets, based on the return value of the function + (True/False). e.g.: + + >>> partition(lambda: x > 3, range(5)) + [1, 2, 3], [4] + """ + results = ([], []) + for item in values: + results[predicate(item)].append(item) + return results
\ No newline at end of file |
