Python django.db.models.fields.FloatField() Examples
The following are 30
code examples of django.db.models.fields.FloatField().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.db.models.fields
, or try the search function
.
Example #1
Source File: djpeewee.py From Quiver-alfred with MIT License | 6 votes |
def get_django_field_map(self): from django.db.models import fields as djf return [ (djf.AutoField, PrimaryKeyField), (djf.BigIntegerField, BigIntegerField), # (djf.BinaryField, BlobField), (djf.BooleanField, BooleanField), (djf.CharField, CharField), (djf.DateTimeField, DateTimeField), # Extends DateField. (djf.DateField, DateField), (djf.DecimalField, DecimalField), (djf.FilePathField, CharField), (djf.FloatField, FloatField), (djf.IntegerField, IntegerField), (djf.NullBooleanField, partial(BooleanField, null=True)), (djf.TextField, TextField), (djf.TimeField, TimeField), (djf.related.ForeignKey, ForeignKeyField), ]
Example #2
Source File: expressions.py From python with Apache License 2.0 | 6 votes |
def convert_value(self, value, expression, connection, context): """ Expressions provide their own converters because users have the option of manually specifying the output_field which may be a different type from the one the database returns. """ field = self.output_field internal_type = field.get_internal_type() if value is None: return value elif internal_type == 'FloatField': return float(value) elif internal_type.endswith('IntegerField'): return int(value) elif internal_type == 'DecimalField': return backend_utils.typecast_decimal(value) return value
Example #3
Source File: expressions.py From openhgsenti with Apache License 2.0 | 6 votes |
def convert_value(self, value, expression, connection, context): """ Expressions provide their own converters because users have the option of manually specifying the output_field which may be a different type from the one the database returns. """ field = self.output_field internal_type = field.get_internal_type() if value is None: return value elif internal_type == 'FloatField': return float(value) elif internal_type.endswith('IntegerField'): return int(value) elif internal_type == 'DecimalField': return backend_utils.typecast_decimal(value) return value
Example #4
Source File: admin.py From django-admin-numeric-filter with MIT License | 6 votes |
def __init__(self, field, request, params, model, model_admin, field_path): super().__init__(field, request, params, model, model_admin, field_path) if not isinstance(field, (DecimalField, IntegerField, FloatField, AutoField)): raise TypeError('Class {} is not supported for {}.'.format(type(self.field), self.__class__.__name__)) self.request = request if self.parameter_name is None: self.parameter_name = self.field.name if self.parameter_name + '_from' in params: value = params.pop(self.parameter_name + '_from') self.used_parameters[self.parameter_name + '_from'] = value if self.parameter_name + '_to' in params: value = params.pop(self.parameter_name + '_to') self.used_parameters[self.parameter_name + '_to'] = value
Example #5
Source File: expressions.py From python2017 with MIT License | 6 votes |
def convert_value(self, value, expression, connection, context): """ Expressions provide their own converters because users have the option of manually specifying the output_field which may be a different type from the one the database returns. """ field = self.output_field internal_type = field.get_internal_type() if value is None: return value elif internal_type == 'FloatField': return float(value) elif internal_type.endswith('IntegerField'): return int(value) elif internal_type == 'DecimalField': return backend_utils.typecast_decimal(value) return value
Example #6
Source File: expressions.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
def convert_value(self, value, expression, connection, context): """ Expressions provide their own converters because users have the option of manually specifying the output_field which may be a different type from the one the database returns. """ field = self.output_field internal_type = field.get_internal_type() if value is None: return value elif internal_type == 'FloatField': return float(value) elif internal_type.endswith('IntegerField'): return int(value) elif internal_type == 'DecimalField': return backend_utils.typecast_decimal(value) return value
Example #7
Source File: bigquery.py From openprescribing with MIT License | 6 votes |
def build_schema_from_model(model): field_mappings = { model_fields.BigIntegerField: "INTEGER", model_fields.CharField: "STRING", model_fields.DateField: "DATE", model_fields.FloatField: "FLOAT", model_fields.DecimalField: "NUMERIC", model_fields.IntegerField: "INTEGER", model_fields.BooleanField: "BOOLEAN", model_fields.NullBooleanField: "BOOLEAN", model_fields.TextField: "STRING", related_fields.ForeignKey: "INTEGER", related_fields.OneToOneField: "INTEGER", } fields = [ (f.name, field_mappings[type(f)]) for f in model._meta.fields if not f.auto_created ] return build_schema(*fields)
Example #8
Source File: aggregates.py From python2017 with MIT License | 5 votes |
def __init__(self, expression, sample=False, **extra): self.function = 'VAR_SAMP' if sample else 'VAR_POP' super(Variance, self).__init__(expression, output_field=FloatField(), **extra)
Example #9
Source File: aggregates.py From python2017 with MIT License | 5 votes |
def __init__(self, expression, sample=False, **extra): self.function = 'STDDEV_SAMP' if sample else 'STDDEV_POP' super(StdDev, self).__init__(expression, output_field=FloatField(), **extra)
Example #10
Source File: aggregates.py From python2017 with MIT License | 5 votes |
def _resolve_output_field(self): source_field = self.get_source_fields()[0] if isinstance(source_field, (IntegerField, DecimalField)): self._output_field = FloatField() super(Avg, self)._resolve_output_field()
Example #11
Source File: expressions.py From python2017 with MIT License | 5 votes |
def __init__(self): super(Random, self).__init__(output_field=fields.FloatField())
Example #12
Source File: expressions.py From openhgsenti with Apache License 2.0 | 5 votes |
def __init__(self): super(Random, self).__init__(output_field=fields.FloatField())
Example #13
Source File: aggregates.py From openhgsenti with Apache License 2.0 | 5 votes |
def __init__(self, expression, sample=False, **extra): self.function = 'VAR_SAMP' if sample else 'VAR_POP' super(Variance, self).__init__(expression, output_field=FloatField(), **extra)
Example #14
Source File: aggregates.py From openhgsenti with Apache License 2.0 | 5 votes |
def __init__(self, expression, sample=False, **extra): self.function = 'STDDEV_SAMP' if sample else 'STDDEV_POP' super(StdDev, self).__init__(expression, output_field=FloatField(), **extra)
Example #15
Source File: aggregates.py From openhgsenti with Apache License 2.0 | 5 votes |
def __init__(self, expression, **extra): output_field = extra.pop('output_field', FloatField()) super(Avg, self).__init__(expression, output_field=output_field, **extra)
Example #16
Source File: expressions.py From python with Apache License 2.0 | 5 votes |
def __init__(self): super(Random, self).__init__(output_field=fields.FloatField())
Example #17
Source File: aggregates.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def __init__(self, expression, **extra): super(Avg, self).__init__(expression, output_field=FloatField(), **extra)
Example #18
Source File: aggregates.py From python with Apache License 2.0 | 5 votes |
def __init__(self, expression, sample=False, **extra): self.function = 'VAR_SAMP' if sample else 'VAR_POP' super(Variance, self).__init__(expression, output_field=FloatField(), **extra)
Example #19
Source File: aggregates.py From python with Apache License 2.0 | 5 votes |
def __init__(self, expression, sample=False, **extra): self.function = 'STDDEV_SAMP' if sample else 'STDDEV_POP' super(StdDev, self).__init__(expression, output_field=FloatField(), **extra)
Example #20
Source File: aggregates.py From python with Apache License 2.0 | 5 votes |
def _resolve_output_field(self): source_field = self.get_source_fields()[0] if isinstance(source_field, (IntegerField, DecimalField)): self._output_field = FloatField() super(Avg, self)._resolve_output_field()
Example #21
Source File: expressions.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def convert_value(self): """ Expressions provide their own converters because users have the option of manually specifying the output_field which may be a different type from the one the database returns. """ field = self.output_field internal_type = field.get_internal_type() if internal_type == 'FloatField': return lambda value, expression, connection: None if value is None else float(value) elif internal_type.endswith('IntegerField'): return lambda value, expression, connection: None if value is None else int(value) elif internal_type == 'DecimalField': return lambda value, expression, connection: None if value is None else Decimal(value) return self._convert_value_noop
Example #22
Source File: aggregates.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def _resolve_output_field(self): source_field = self.get_source_fields()[0] if isinstance(source_field, (IntegerField, DecimalField)): return FloatField() return super()._resolve_output_field()
Example #23
Source File: problems.py From online-judge with GNU Affero General Public License v3.0 | 5 votes |
def hot_problems(duration, limit): cache_key = 'hot_problems:%d:%d' % (duration.total_seconds(), limit) qs = cache.get(cache_key) if qs is None: qs = Problem.get_public_problems() \ .filter(submission__date__gt=timezone.now() - duration, points__gt=3, points__lt=25) qs0 = qs.annotate(k=Count('submission__user', distinct=True)).order_by('-k').values_list('k', flat=True) if not qs0: return [] # make this an aggregate mx = float(qs0[0]) qs = qs.annotate(unique_user_count=Count('submission__user', distinct=True)) # fix braindamage in excluding CE qs = qs.annotate(submission_volume=Count(Case( When(submission__result='AC', then=1), When(submission__result='WA', then=1), When(submission__result='IR', then=1), When(submission__result='RTE', then=1), When(submission__result='TLE', then=1), When(submission__result='OLE', then=1), output_field=FloatField(), ))) qs = qs.annotate(ac_volume=Count(Case( When(submission__result='AC', then=1), output_field=FloatField(), ))) qs = qs.filter(unique_user_count__gt=max(mx / 3.0, 1)) qs = qs.annotate(ordering=ExpressionWrapper( 0.5 * F('points') * (0.4 * F('ac_volume') / F('submission_volume') + 0.6 * F('ac_rate')) + 100 * e ** (F('unique_user_count') / mx), output_field=FloatField(), )).order_by('-ordering').defer('description')[:limit] cache.set(cache_key, qs, 900) return qs
Example #24
Source File: expressions.py From bioforum with MIT License | 5 votes |
def convert_value(self): """ Expressions provide their own converters because users have the option of manually specifying the output_field which may be a different type from the one the database returns. """ field = self.output_field internal_type = field.get_internal_type() if internal_type == 'FloatField': return lambda value, expression, connection: None if value is None else float(value) elif internal_type.endswith('IntegerField'): return lambda value, expression, connection: None if value is None else int(value) elif internal_type == 'DecimalField': return lambda value, expression, connection: None if value is None else Decimal(value) return self._convert_value_noop
Example #25
Source File: aggregates.py From bioforum with MIT License | 5 votes |
def _resolve_output_field(self): source_field = self.get_source_fields()[0] if isinstance(source_field, (IntegerField, DecimalField)): return FloatField() return super()._resolve_output_field()
Example #26
Source File: admin.py From django-admin-numeric-filter with MIT License | 5 votes |
def choices(self, changelist): total = self.q.all().count() min_value = self.q.all().aggregate( min=Min(self.parameter_name) ).get('min', 0) if total > 1: max_value = self.q.all().aggregate( max=Max(self.parameter_name) ).get('max', 0) else: max_value = None if isinstance(self.field, (FloatField, DecimalField)): decimals = self.MAX_DECIMALS step = self.STEP if self.STEP else self._get_min_step(self.MAX_DECIMALS) else: decimals = 0 step = self.STEP if self.STEP else 1 return ({ 'decimals': decimals, 'step': step, 'parameter_name': self.parameter_name, 'request': self.request, 'min': min_value, 'max': max_value, 'value_from': self.used_parameters.get(self.parameter_name + '_from', min_value), 'value_to': self.used_parameters.get(self.parameter_name + '_to', max_value), 'form': SliderNumericForm(name=self.parameter_name, data={ self.parameter_name + '_from': self.used_parameters.get(self.parameter_name + '_from', min_value), self.parameter_name + '_to': self.used_parameters.get(self.parameter_name + '_to', max_value), }) }, )
Example #27
Source File: admin.py From django-admin-numeric-filter with MIT License | 5 votes |
def __init__(self, field, request, params, model, model_admin, field_path): super().__init__(field, request, params, model, model_admin, field_path) if not isinstance(field, (DecimalField, IntegerField, FloatField, AutoField)): raise TypeError('Class {} is not supported for {}.'.format(type(self.field), self.__class__.__name__)) self.request = request if self.parameter_name is None: self.parameter_name = self.field.name if self.parameter_name in params: value = params.pop(self.parameter_name) self.used_parameters[self.parameter_name] = value
Example #28
Source File: fields.py From django-osm-field with MIT License | 5 votes |
def formfield(self, **kwargs): """ :returns: A :class:`~django.forms.FloatField` with ``max_value`` 180 and ``min_value`` -180. """ kwargs.update({"max_value": 180, "min_value": -180}) return super(LongitudeField, self).formfield(**kwargs)
Example #29
Source File: fields.py From django-osm-field with MIT License | 5 votes |
def formfield(self, **kwargs): """ :returns: A :class:`~django.forms.FloatField` with ``max_value`` 90 and ``min_value`` -90. """ kwargs.update({"max_value": 90, "min_value": -90}) return super(LatitudeField, self).formfield(**kwargs)
Example #30
Source File: expressions.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def __init__(self): super(Random, self).__init__(output_field=fields.FloatField())