本文整理汇总了Python中django.db.models.FloatField方法的典型用法代码示例。如果您正苦于以下问题:Python models.FloatField方法的具体用法?Python models.FloatField怎么用?Python models.FloatField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models
的用法示例。
在下文中一共展示了models.FloatField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import FloatField [as 别名]
def display_for_field(value, field):
from xadmin.views.list import EMPTY_CHANGELIST_VALUE
if field.flatchoices:
return dict(field.flatchoices).get(value, EMPTY_CHANGELIST_VALUE)
# NullBooleanField needs special-case null-handling, so it comes
# before the general null test.
elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField):
return boolean_icon(value)
elif value is None:
return EMPTY_CHANGELIST_VALUE
elif isinstance(field, models.DateTimeField):
return formats.localize(tz_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, models.FloatField):
return formats.number_format(value)
elif isinstance(field.rel, models.ManyToManyRel):
return ', '.join([smart_text(obj) for obj in value.all()])
else:
return smart_text(value)
示例2: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import FloatField [as 别名]
def display_for_field(value, field):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
if field.flatchoices:
return dict(field.flatchoices).get(value, EMPTY_CHANGELIST_VALUE)
# NullBooleanField needs special-case null-handling, so it comes
# before the general null test.
elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField):
return _boolean_icon(value)
elif value is None:
return EMPTY_CHANGELIST_VALUE
elif isinstance(field, models.DateTimeField):
return formats.localize(timezone.template_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, models.FloatField):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
else:
return smart_text(value)
示例3: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import FloatField [as 别名]
def display_for_field(value, field, empty_value_display):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
if getattr(field, 'flatchoices', None):
return dict(field.flatchoices).get(value, empty_value_display)
# NullBooleanField needs special-case null-handling, so it comes
# before the general null test.
elif isinstance(field, (models.BooleanField, models.NullBooleanField)):
return _boolean_icon(value)
elif value is None:
return empty_value_display
elif isinstance(field, models.DateTimeField):
return formats.localize(timezone.template_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, (models.IntegerField, models.FloatField)):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
else:
return display_for_value(value, empty_value_display)
示例4: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import FloatField [as 别名]
def display_for_field(value, field):
from xadmin.views.list import EMPTY_CHANGELIST_VALUE
if field.flatchoices:
return dict(field.flatchoices).get(value, EMPTY_CHANGELIST_VALUE)
# NullBooleanField needs special-case null-handling, so it comes
# before the general null test.
elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField):
return boolean_icon(value)
elif value is None:
return EMPTY_CHANGELIST_VALUE
elif isinstance(field, models.DateTimeField):
return formats.localize(tz_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, models.FloatField):
return formats.number_format(value)
elif isinstance(field.remote_field, models.ManyToManyRel):
return ', '.join([smart_text(obj) for obj in value.all()])
else:
return smart_text(value)
示例5: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import FloatField [as 别名]
def display_for_field(value, field, empty_value_display):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
if getattr(field, 'flatchoices', None):
return dict(field.flatchoices).get(value, empty_value_display)
# BooleanField needs special-case null-handling, so it comes before the
# general null test.
elif isinstance(field, models.BooleanField):
return _boolean_icon(value)
elif value is None:
return empty_value_display
elif isinstance(field, models.DateTimeField):
return formats.localize(timezone.template_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, (models.IntegerField, models.FloatField)):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
else:
return display_for_value(value, empty_value_display)
示例6: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import FloatField [as 别名]
def display_for_field(value, field, empty_value_display):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
if getattr(field, 'flatchoices', None):
return dict(field.flatchoices).get(value, empty_value_display)
# NullBooleanField needs special-case null-handling, so it comes
# before the general null test.
elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField):
return _boolean_icon(value)
elif value is None:
return empty_value_display
elif isinstance(field, models.DateTimeField):
return formats.localize(timezone.template_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, (models.IntegerField, models.FloatField)):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
else:
return display_for_value(value, empty_value_display)
示例7: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import FloatField [as 别名]
def display_for_field(value, field, empty_value_display):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
if field.flatchoices:
return dict(field.flatchoices).get(value, empty_value_display)
# NullBooleanField needs special-case null-handling, so it comes
# before the general null test.
elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField):
return _boolean_icon(value)
elif value is None:
return empty_value_display
elif isinstance(field, models.DateTimeField):
return formats.localize(timezone.template_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, (models.IntegerField, models.FloatField)):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
else:
return smart_text(value)
示例8: as_sql
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import FloatField [as 别名]
def as_sql(self, compiler, connection):
if connection.ops.geography:
# Geography fields support area calculation, returns square meters.
self.output_field = AreaField('sq_m')
elif not self.output_field.geodetic(connection):
# Getting the area units of the geographic field.
units = self.output_field.units_name(connection)
if units:
self.output_field = AreaField(
AreaMeasure.unit_attname(self.output_field.units_name(connection))
)
else:
self.output_field = FloatField()
else:
# TODO: Do we want to support raw number areas for geodetic fields?
raise NotImplementedError('Area on geodetic coordinate systems not supported.')
return super(Area, self).as_sql(compiler, connection)
示例9: display_for_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import FloatField [as 别名]
def display_for_field(value, field):
from xadmin.views.list import EMPTY_CHANGELIST_VALUE
if field.flatchoices:
return dict(field.flatchoices).get(value, EMPTY_CHANGELIST_VALUE)
# NullBooleanField needs special-case null-handling, so it comes
# before the general null test.
elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField):
return boolean_icon(value)
elif value is None:
return EMPTY_CHANGELIST_VALUE
elif isinstance(field, models.DateTimeField):
return formats.localize(tz_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, models.FloatField):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
else:
return smart_text(value)
示例10: document_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import FloatField [as 别名]
def document_field(field):
"""
The default ``field_factory`` method for converting Django field instances to ``elasticsearch_dsl.Field`` instances.
Auto-created fields (primary keys, for example) and one-to-many fields (reverse FK relationships) are skipped.
"""
if field.auto_created or field.one_to_many:
return None
if field.many_to_many:
return RawMultiString
defaults = {
models.DateField: dsl.Date(),
models.DateTimeField: dsl.Date(),
models.IntegerField: dsl.Long(),
models.PositiveIntegerField: dsl.Long(),
models.BooleanField: dsl.Boolean(),
models.NullBooleanField: dsl.Boolean(),
models.SlugField: dsl.String(index='not_analyzed'),
models.DecimalField: dsl.Double(),
models.FloatField: dsl.Float(),
}
return defaults.get(field.__class__, RawString)
示例11: test_add_field_ignore_swapped
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import FloatField [as 别名]
def test_add_field_ignore_swapped(self):
"""
Tests the AddField operation.
"""
# Test the state alteration
operation = migrations.AddField(
"Pony",
"height",
models.FloatField(null=True, default=5),
)
project_state, new_state = self.make_test_state("test_adfligsw", operation)
# Test the database alteration
self.assertTableNotExists("test_adfligsw_pony")
with connection.schema_editor() as editor:
operation.database_forwards("test_adfligsw", editor, project_state, new_state)
self.assertTableNotExists("test_adfligsw_pony")
# And test reversal
with connection.schema_editor() as editor:
operation.database_backwards("test_adfligsw", editor, new_state, project_state)
self.assertTableNotExists("test_adfligsw_pony")
示例12: schema_type_from_model_field
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import FloatField [as 别名]
def schema_type_from_model_field(field):
field_class = field.__class__
if field_class == models.FloatField:
return 'number', None
elif field_class in [models.CharField, models.TextField]:
return 'string', None
elif field_class == models.DateTimeField:
return 'string', 'date-time'
elif field_class == models.BooleanField:
return 'boolean', None
elif field_class == models.ForeignKey:
return 'string', 'url'
else:
raise NotImplementedError('Field type %s not recognized' % field_class)
# TODO: this should get the URL dynamically
示例13: get_item_report
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import FloatField [as 别名]
def get_item_report(qs, total_log_count, **kwargs):
if qs.count() == 0:
return None
min_count = kwargs.get('min_count', max(1, int(MINIMUM_THRESHOLD * total_log_count)))
results = list(
qs.values(
'item',
name=F('item__name'),
icon=F('item__icon'),
).annotate(
count=Count('pk'),
min=Min('quantity'),
max=Max('quantity'),
avg=Avg('quantity'),
drop_chance=Cast(Count('pk'), FloatField()) / total_log_count * 100,
qty_per_100=Cast(Sum('quantity'), FloatField()) / total_log_count * 100,
).filter(count__gt=min_count).order_by('-count')
)
return results
示例14: test_alter_fk_non_fk
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import FloatField [as 别名]
def test_alter_fk_non_fk(self):
"""
Altering an FK to a non-FK works (#23244)
"""
# Test the state alteration
operation = migrations.AlterField(
model_name="Rider",
name="pony",
field=models.FloatField(),
)
project_state, new_state = self.make_test_state("test_afknfk", operation, related_model=True)
# Test the database alteration
self.assertColumnExists("test_afknfk_rider", "pony_id")
self.assertColumnNotExists("test_afknfk_rider", "pony")
with connection.schema_editor() as editor:
operation.database_forwards("test_afknfk", editor, project_state, new_state)
self.assertColumnExists("test_afknfk_rider", "pony")
self.assertColumnNotExists("test_afknfk_rider", "pony_id")
# And test reversal
with connection.schema_editor() as editor:
operation.database_backwards("test_afknfk", editor, new_state, project_state)
self.assertColumnExists("test_afknfk_rider", "pony_id")
self.assertColumnNotExists("test_afknfk_rider", "pony")
示例15: index
# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import FloatField [as 别名]
def index(request, event=None):
event = viewutil.get_event(event)
eventParams = {}
if event.id:
eventParams['event'] = event.id
agg = Donation.objects.filter(
transactionstate='COMPLETED', testdonation=False, **eventParams
).aggregate(
amount=Cast(Coalesce(Sum('amount'), 0), output_field=FloatField()),
count=Count('amount'),
max=Cast(Coalesce(Max('amount'), 0), output_field=FloatField()),
avg=Cast(Coalesce(Avg('amount'), 0), output_field=FloatField()),
)
agg['target'] = float(event.targetamount)
count = {
'runs': filters.run_model_query('run', eventParams).count(),
'prizes': filters.run_model_query('prize', eventParams).count(),
'bids': filters.run_model_query('bid', eventParams).count(),
'donors': filters.run_model_query('donorcache', eventParams)
.values('donor')
.distinct()
.count(),
}
if 'json' in request.GET:
return HttpResponse(
json.dumps({'count': count, 'agg': agg}, ensure_ascii=False,),
content_type='application/json;charset=utf-8',
)
return views_common.tracker_response(
request, 'tracker/index.html', {'agg': agg, 'count': count, 'event': event}
)