Ticket #26638: patch26638.txt

File patch26638.txt, 953 bytes (added by Maxime Lorant, 8 years ago)
Line 
1diff --git a/django/db/models/query.py b/django/db/models/query.py
2index 8bd981d..03ee312 100644
3--- a/django/db/models/query.py
4+++ b/django/db/models/query.py
5@@ -463,6 +463,9 @@ class QuerySet(object):
6 Returns a tuple of (object, created), where created is a boolean
7 specifying whether an object was created.
8 """
9+ if callable(defaults):
10+ defaults = defaults()
11+
12 lookup, params = self._extract_model_params(defaults, **kwargs)
13 # The get() needs to be targeted at the write database in order
14 # to avoid potential transaction consistency problems.
15@@ -480,6 +483,9 @@ class QuerySet(object):
16 specifying whether an object was created.
17 """
18 defaults = defaults or {}
19+ if callable(defaults):
20+ defaults = defaults()
21+
22 lookup, params = self._extract_model_params(defaults, **kwargs)
23 self._for_write = True
24 try:
Back to Top