mirror of
https://github.com/django/django.git
synced 2025-10-29 08:36:09 +00:00
Fixed pk uniqueness validation for new objects created outside of a ModelForm. Also removed need for ModelForm to poke at Model._state.adding, keeping it an internal ORM concern.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14613 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -284,6 +284,8 @@ class QuerySet(object):
|
||||
|
||||
# Store the source database of the object
|
||||
obj._state.db = self.db
|
||||
# This object came from the database; it's not being added.
|
||||
obj._state.adding = False
|
||||
|
||||
for i, k in enumerate(extra_select):
|
||||
setattr(obj, k, row[i])
|
||||
@@ -1204,6 +1206,7 @@ def get_cached_row(klass, row, index_start, using, max_depth=0, cur_depth=0,
|
||||
# If an object was retrieved, set the database state.
|
||||
if obj:
|
||||
obj._state.db = using
|
||||
obj._state.adding = False
|
||||
|
||||
index_end = index_start + field_count + offset
|
||||
# Iterate over each related object, populating any
|
||||
@@ -1387,6 +1390,7 @@ class RawQuerySet(object):
|
||||
setattr(instance, field, value)
|
||||
|
||||
instance._state.db = self.query.using
|
||||
instance._state.adding = False
|
||||
|
||||
return instance
|
||||
|
||||
|
||||
Reference in New Issue
Block a user