Simplified some imports for database functions.

Used more specific modules to reduce the risk of circular imports.
This commit is contained in:
Nick Pope 2019-01-09 00:21:31 +00:00 committed by Tim Graham
parent 36fceeec88
commit 99b3ab2781
5 changed files with 16 additions and 13 deletions

View File

@ -1,5 +1,5 @@
"""Database functions that do comparisons or type conversions.""" """Database functions that do comparisons or type conversions."""
from django.db.models import Func from django.db.models.expressions import Func
class Cast(Func): class Cast(Func):

View File

@ -1,12 +1,12 @@
from datetime import datetime from datetime import datetime
from django.conf import settings from django.conf import settings
from django.db.models import ( from django.db.models.expressions import Func
DateField, DateTimeField, DurationField, Field, Func, IntegerField, from django.db.models.fields import (
TimeField, Transform, fields, DateField, DateTimeField, DurationField, Field, IntegerField, TimeField,
) )
from django.db.models.lookups import ( from django.db.models.lookups import (
YearExact, YearGt, YearGte, YearLt, YearLte, Transform, YearExact, YearGt, YearGte, YearLt, YearLte,
) )
from django.utils import timezone from django.utils import timezone
@ -157,7 +157,7 @@ ExtractIsoYear.register_lookup(YearLte)
class Now(Func): class Now(Func):
template = 'CURRENT_TIMESTAMP' template = 'CURRENT_TIMESTAMP'
output_field = fields.DateTimeField() output_field = DateTimeField()
def as_postgresql(self, compiler, connection, **extra_context): def as_postgresql(self, compiler, connection, **extra_context):
# PostgreSQL's CURRENT_TIMESTAMP means "the time at the start of the # PostgreSQL's CURRENT_TIMESTAMP means "the time at the start of the

View File

@ -1,10 +1,10 @@
import math import math
import sys import sys
from django.db.models import ( from django.db.models.expressions import Func
DecimalField, FloatField, Func, IntegerField, Transform, from django.db.models.fields import DecimalField, FloatField, IntegerField
)
from django.db.models.functions import Cast from django.db.models.functions import Cast
from django.db.models.lookups import Transform
class DecimalInputMixin: class DecimalInputMixin:

View File

@ -1,5 +1,7 @@
from django.db.models import Func, IntegerField, Transform, Value, fields from django.db.models.expressions import Func, Value
from django.db.models.fields import IntegerField
from django.db.models.functions import Coalesce from django.db.models.functions import Coalesce
from django.db.models.lookups import Transform
class BytesToCharFieldConversionMixin: class BytesToCharFieldConversionMixin:
@ -124,7 +126,7 @@ class Length(Transform):
"""Return the number of characters in the expression.""" """Return the number of characters in the expression."""
function = 'LENGTH' function = 'LENGTH'
lookup_name = 'length' lookup_name = 'length'
output_field = fields.IntegerField() output_field = IntegerField()
def as_mysql(self, compiler, connection, **extra_context): def as_mysql(self, compiler, connection, **extra_context):
return super().as_sql(compiler, connection, function='CHAR_LENGTH', **extra_context) return super().as_sql(compiler, connection, function='CHAR_LENGTH', **extra_context)
@ -207,7 +209,7 @@ class StrIndex(Func):
""" """
function = 'INSTR' function = 'INSTR'
arity = 2 arity = 2
output_field = fields.IntegerField() output_field = IntegerField()
def as_postgresql(self, compiler, connection, **extra_context): def as_postgresql(self, compiler, connection, **extra_context):
return super().as_sql(compiler, connection, function='STRPOS', **extra_context) return super().as_sql(compiler, connection, function='STRPOS', **extra_context)

View File

@ -1,4 +1,5 @@
from django.db.models import FloatField, Func, IntegerField from django.db.models.expressions import Func
from django.db.models.fields import FloatField, IntegerField
__all__ = [ __all__ = [
'CumeDist', 'DenseRank', 'FirstValue', 'Lag', 'LastValue', 'Lead', 'CumeDist', 'DenseRank', 'FirstValue', 'Lag', 'LastValue', 'Lead',