summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorBrian Rosner <brosner@gmail.com>2008-06-10 04:03:09 +0000
committerBrian Rosner <brosner@gmail.com>2008-06-10 04:03:09 +0000
commit4530a408c40647c195f27f81da1315e98e956f96 (patch)
treeed8290751a7e284b9f030f4da97b422067ca9c95 /django/db
parent3b92ced51856e740cd6fb3d3e5bb8ea932bd276e (diff)
newforms-admin: Merged from trunk up to [7602].
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7604 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db')
-rw-r--r--django/db/models/base.py13
-rw-r--r--django/db/models/options.py10
-rw-r--r--django/db/models/query.py4
-rw-r--r--django/db/models/sql/query.py16
4 files changed, 32 insertions, 11 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 01c2f31794..a253f38f47 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -287,12 +287,17 @@ class Model(object):
meta = cls._meta
signal = False
- for parent, field in meta.parents.items():
- self.save_base(raw, parent)
- setattr(self, field.attname, self._get_pk_val(parent._meta))
+ # If we are in a raw save, save the object exactly as presented.
+ # That means that we don't try to be smart about saving attributes
+ # that might have come from the parent class - we just save the
+ # attributes we have been given to the class we have been given.
+ if not raw:
+ for parent, field in meta.parents.items():
+ self.save_base(raw, parent)
+ setattr(self, field.attname, self._get_pk_val(parent._meta))
non_pks = [f for f in meta.local_fields if not f.primary_key]
-
+
# First, try an UPDATE. If that doesn't update anything, do an INSERT.
pk_val = self._get_pk_val(meta)
# Note: the comparison with '' is required for compatibility with
diff --git a/django/db/models/options.py b/django/db/models/options.py
index 3948a5fd10..c78ab1cd48 100644
--- a/django/db/models/options.py
+++ b/django/db/models/options.py
@@ -55,8 +55,12 @@ class Options(object):
# Next, apply any overridden values from 'class Meta'.
if self.meta:
meta_attrs = self.meta.__dict__.copy()
- del meta_attrs['__module__']
- del meta_attrs['__doc__']
+ for name in self.meta.__dict__:
+ # Ignore any private attributes that Django doesn't care about.
+ # NOTE: We can't modify a dictionary's contents while looping
+ # over it, so we loop over the *original* dictionary instead.
+ if name.startswith('_'):
+ del meta_attrs[name]
for attr_name in DEFAULT_NAMES:
if attr_name in meta_attrs:
setattr(self, attr_name, meta_attrs.pop(attr_name))
@@ -97,7 +101,7 @@ class Options(object):
# field.
field = self.parents.value_for_index(0)
field.primary_key = True
- self.pk = field
+ self.setup_pk(field)
else:
auto = AutoField(verbose_name='ID', primary_key=True,
auto_created=True)
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 6b341ba9ab..12731caa94 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -292,6 +292,8 @@ class QuerySet(object):
Updates all elements in the current QuerySet, setting all the given
fields to the appropriate values.
"""
+ assert self.query.can_filter(), \
+ "Cannot update a query once a slice has been taken."
query = self.query.clone(sql.UpdateQuery)
query.add_update_values(kwargs)
query.execute_sql(None)
@@ -306,6 +308,8 @@ class QuerySet(object):
code (it requires too much poking around at model internals to be
useful at that level).
"""
+ assert self.query.can_filter(), \
+ "Cannot update a query once a slice has been taken."
query = self.query.clone(sql.UpdateQuery)
query.add_update_fields(values)
query.execute_sql(None)
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index a6957bab7b..3044882a86 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -851,7 +851,7 @@ class Query(object):
return alias
def fill_related_selections(self, opts=None, root_alias=None, cur_depth=1,
- used=None, requested=None, restricted=None):
+ used=None, requested=None, restricted=None, nullable=None):
"""
Fill in the information needed for a select_related query. The current
depth is measured as the number of connections away from the root model
@@ -883,6 +883,10 @@ class Query(object):
(not restricted and f.null) or f.rel.parent_link):
continue
table = f.rel.to._meta.db_table
+ if nullable or f.null:
+ promote = True
+ else:
+ promote = False
if model:
int_opts = opts
alias = root_alias
@@ -891,12 +895,12 @@ class Query(object):
int_opts = int_model._meta
alias = self.join((alias, int_opts.db_table, lhs_col,
int_opts.pk.column), exclusions=used,
- promote=f.null)
+ promote=promote)
else:
alias = root_alias
alias = self.join((alias, table, f.column,
f.rel.get_related_field().column), exclusions=used,
- promote=f.null)
+ promote=promote)
used.add(alias)
self.related_select_cols.extend([(alias, f2.column)
for f2 in f.rel.to._meta.fields])
@@ -905,8 +909,12 @@ class Query(object):
next = requested.get(f.name, {})
else:
next = False
+ if f.null is not None:
+ new_nullable = f.null
+ else:
+ new_nullable = None
self.fill_related_selections(f.rel.to._meta, alias, cur_depth + 1,
- used, next, restricted)
+ used, next, restricted, new_nullable)
def add_filter(self, filter_expr, connector=AND, negate=False, trim=False,
can_reuse=None):