本文整理汇总了Python中django.db.models.fields.TextField方法的典型用法代码示例。如果您正苦于以下问题:Python fields.TextField方法的具体用法?Python fields.TextField怎么用?Python fields.TextField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.fields
的用法示例。
在下文中一共展示了fields.TextField方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_django_field_map
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import TextField [as 别名]
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),
]
示例2: build_schema_from_model
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import TextField [as 别名]
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)
示例3: application_details
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import TextField [as 别名]
def application_details(application):
all_fields = application._meta.fields # pylint:disable=protected-access
text_fields = [
(field, getattr(application, field.name))
for field in all_fields
if isinstance(field, TextField)
]
familiarities = []
lead = 'familiarity_'
for field in (f for f in all_fields if f.name.startswith(lead)):
if field.name == 'familiarity_sr':
short_label = 'self-rescue'
else:
short_label = field.name[len(lead) :].replace('_', ' ')
response = getattr(application, 'get_' + field.name + '_display')()
familiarities.append((short_label, response))
return {'familiarities': familiarities, 'text_fields': text_fields}
示例4: get_comparison_class
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import TextField [as 别名]
def get_comparison_class(self):
# Hide fields with hidden widget
widget_override = self.widget_overrides().get(self.field_name, None)
if widget_override and widget_override.is_hidden:
return
try:
field = self.db_field
if field.choices:
return compare.ChoiceFieldComparison
if field.is_relation:
if isinstance(field, TaggableManager):
return compare.TagsFieldComparison
elif field.many_to_many:
return compare.M2MFieldComparison
return compare.ForeignObjectComparison
if isinstance(field, RichTextField):
return compare.RichTextFieldComparison
if isinstance(field, (CharField, TextField)):
return compare.TextFieldComparison
except FieldDoesNotExist:
pass
return compare.FieldComparison
示例5: LeaderApplicationForm
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import TextField [as 别名]
def LeaderApplicationForm(*args, **kwargs):
""" Factory form for applying to be a leader in any activity. """
activity = kwargs.pop('activity')
class DynamicActivityForm(DjangularRequiredModelForm):
class Meta:
exclude = ['archived', 'year', 'participant', 'previous_rating']
model = models.LeaderApplication.model_from_activity(activity)
widgets = {
field.name: forms.Textarea(attrs={'rows': 4})
for field in model._meta.fields # pylint: disable=protected-access
if isinstance(field, TextField)
}
def clean(self):
cleaned_data = super().clean()
if not models.LeaderApplication.accepting_applications(activity):
raise ValidationError("Not currently accepting applications!")
return cleaned_data
def __init__(self, *args, **kwargs):
# TODO: Errors on args, where args is a single tuple of the view
# super().__init__(*args, **kwargs)
super().__init__(**kwargs)
return DynamicActivityForm(*args, **kwargs)