Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __rtruediv__(self, other):
return ArithmeticExpression(Arithmetic.div, self.wrap_constant(other), self)
def __add__(self, other):
return ArithmeticExpression(Arithmetic.add, self, other)
def __sub__(self, other):
return ArithmeticExpression(Arithmetic.sub, self, self.wrap_constant(other))
def __sub__(self, other):
return ArithmeticExpression(Arithmetic.sub, self, other)
def __rmul__(self, other):
return ArithmeticExpression(Arithmetic.mul, self.wrap_constant(other), self)
def __mul__(self, other):
return ArithmeticExpression(Arithmetic.mul, self, self.wrap_constant(other))
def __mul__(self, other):
return ArithmeticExpression(Arithmetic.mul, self, other)
def __add__(self, other):
return ArithmeticExpression(Arithmetic.add, self, self.wrap_constant(other))
name = arithmetic_expression_or_field.name
try:
arithmetic_expression_or_field.name = model._meta.fields_db_projection[name]
field_object = model._meta.fields_map.get(name, None)
if field_object:
func = field_object.get_for_dialect(
model._meta.db.capabilities.dialect, "function_cast"
)
if func:
arithmetic_expression_or_field = func(
field_object, arithmetic_expression_or_field
)
except KeyError:
raise FieldError(f"There is no non-virtual field {name} on Model {model.__name__}")
elif isinstance(arithmetic_expression_or_field, ArithmeticExpression):
left = arithmetic_expression_or_field.left
right = arithmetic_expression_or_field.right
(
arithmetic_expression_or_field.left,
left_field_object,
) = cls.resolver_arithmetic_expression(model, left)
if left_field_object:
if field_object and type(field_object) != type(left_field_object):
raise FieldError(
"Cannot use arithmetic expression between different field type"
)
field_object = left_field_object
(
arithmetic_expression_or_field.right,
right_field_object,