summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/aggregates.py4
-rw-r--r--django/db/models/sql/compiler.py8
-rw-r--r--django/db/models/sql/query.py2
-rw-r--r--django/db/models/sql/subqueries.py2
4 files changed, 8 insertions, 8 deletions
diff --git a/django/db/models/sql/aggregates.py b/django/db/models/sql/aggregates.py
index 1b65847b7f..23b79923d1 100644
--- a/django/db/models/sql/aggregates.py
+++ b/django/db/models/sql/aggregates.py
@@ -112,7 +112,7 @@ class StdDev(Aggregate):
def __init__(self, col, sample=False, **extra):
super(StdDev, self).__init__(col, **extra)
- self.sql_function = sample and 'STDDEV_SAMP' or 'STDDEV_POP'
+ self.sql_function = 'STDDEV_SAMP' if sample else 'STDDEV_POP'
class Sum(Aggregate):
sql_function = 'SUM'
@@ -122,4 +122,4 @@ class Variance(Aggregate):
def __init__(self, col, sample=False, **extra):
super(Variance, self).__init__(col, **extra)
- self.sql_function = sample and 'VAR_SAMP' or 'VAR_POP'
+ self.sql_function = 'VAR_SAMP' if sample else 'VAR_POP'
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 7b7c430420..bbe310c8c3 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -512,7 +512,7 @@ class SQLCompiler(object):
# Extra tables can end up in self.tables, but not in the
# alias_map if they aren't in a join. That's OK. We skip them.
continue
- alias_str = (alias != name and ' %s' % alias or '')
+ alias_str = '' if alias == name else (' %s' % alias)
if join_type and not first:
extra_cond = join_field.get_extra_restriction(
self.query.where_class, alias, lhs)
@@ -532,7 +532,7 @@ class SQLCompiler(object):
(qn(lhs), qn2(lhs_col), qn(alias), qn2(rhs_col)))
result.append('%s)' % extra_sql)
else:
- connector = not first and ', ' or ''
+ connector = '' if first else ', '
result.append('%s%s%s' % (connector, qn(name), alias_str))
first = False
for t in self.query.extra_tables:
@@ -541,7 +541,7 @@ class SQLCompiler(object):
# calls increments the refcount, so an alias refcount of one means
# this is the only reference.
if alias not in self.query.alias_map or self.query.alias_refcount[alias] == 1:
- connector = not first and ', ' or ''
+ connector = '' if first else ', '
result.append('%s%s' % (connector, qn(alias)))
first = False
return result, from_params
@@ -959,7 +959,7 @@ class SQLUpdateCompiler(SQLCompiler):
related queries are not available.
"""
cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
- rows = cursor and cursor.rowcount or 0
+ rows = cursor.rowcount if cursor else 0
is_empty = cursor is None
del cursor
for query in self.query.get_related_updates():
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 6db2bf6e12..0a4152587d 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -532,7 +532,7 @@ class Query(object):
# Ordering uses the 'rhs' ordering, unless it has none, in which case
# the current ordering is used.
- self.order_by = rhs.order_by and rhs.order_by[:] or self.order_by
+ self.order_by = rhs.order_by[:] if rhs.order_by else self.order_by
self.extra_order_by = rhs.extra_order_by or self.extra_order_by
def deferred_to_data(self, target, callback):
diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py
index fae42b4be2..20770162c9 100644
--- a/django/db/models/sql/subqueries.py
+++ b/django/db/models/sql/subqueries.py
@@ -245,7 +245,7 @@ class DateQuery(Query):
self.clear_select_clause()
self.select = [SelectInfo(select, None)]
self.distinct = True
- self.order_by = order == 'ASC' and [1] or [-1]
+ self.order_by = [1] if order == 'ASC' else [-1]
if field.null:
self.add_filter(("%s__isnull" % field_name, False))