Python django.db.models.fields 模块,DecimalField() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用django.db.models.fields.DecimalField()

项目:django-couchbase    作者:aswinkp    | 项目源码 | 文件源码
def from_dict(self, dict_payload):
        for field in self._meta.fields:
            if field.name not in dict_payload:
                continue
            if isinstance(field, EmbeddedModelField):
                self.from_dict_nested(field.name, field.embedded_model, dict_payload)
                continue
            if isinstance(field, ListField):
                if isinstance(field.item_field, EmbeddedModelField):
                    self.from_dict_nested_list(field.name, field.item_field.embedded_model, dict_payload)
                continue
            if isinstance(field, DateTimeField):
                self._date_from_string(field.name, dict_payload.get(field.name))
            elif isinstance(field, DecimalField):
                self._decimal_from_string(field.name, dict_payload.get(field.name))
            elif field.name in dict_payload:
                setattr(self, field.name, dict_payload[field.name])
        if 'id' in dict_payload.keys():
            self.id = dict_payload['id']
项目:django-couchbase-demo    作者:aswinkp    | 项目源码 | 文件源码
def from_dict(self, dict_payload):
        for field in self._meta.fields:
            if field.name not in dict_payload:
                continue
            if isinstance(field, EmbeddedModelField):
                self.from_dict_nested(field.name, field.embedded_model, dict_payload)
                continue
            if isinstance(field, ListField):
                if isinstance(field.item_field, EmbeddedModelField):
                    self.from_dict_nested_list(field.name, field.item_field.embedded_model, dict_payload)
                continue
            if isinstance(field, DateTimeField):
                self._date_from_string(field.name, dict_payload.get(field.name))
            elif isinstance(field, DecimalField):
                self._decimal_from_string(field.name, dict_payload.get(field.name))
            elif field.name in dict_payload:
                setattr(self, field.name, dict_payload[field.name])
        if 'id' in dict_payload.keys():
            self.id = dict_payload['id']
项目:Quiver-alfred    作者:danielecook    | 项目源码 | 文件源码
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),
        ]
项目:metrics    作者:Jeremy-Friedman    | 项目源码 | 文件源码
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),
        ]
项目:metrics    作者:Jeremy-Friedman    | 项目源码 | 文件源码
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),
        ]
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def set_decimal(instance, field, max_digits=10):
    """ DecimalField """
    max_digits = min(max_digits, field.max_digits)
    min_value = -10 ** max_digits
    max_value = 10 ** max_digits
    for validator in field.validators:
        if isinstance(validator, MinValueValidator):
            min_value = max(min_value, validator.limit_value)
        if isinstance(validator, MaxValueValidator):
            max_value = min(max_value, validator.limit_value)

    value = random.randint(min_value, max_value)
    value = Decimal(value) / 10 ** field.decimal_places

    setattr(instance, field.name, value)
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
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()
项目:liberator    作者:libscie    | 项目源码 | 文件源码
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()
项目:LatinSounds_AppEnviaMail    作者:G3ek-aR    | 项目源码 | 文件源码
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()