From 7deb25b8dd5aa1ed02b5e30cbc67cd1fb0c3d6e6 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Fri, 9 Sep 2011 19:22:28 +0000 Subject: 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 --- django/utils/functional.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'django/utils') 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 -- cgit v1.3