我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用django.db.models.fields.TextField()。
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), ]
def set_text(instance, field, paragraphs=1, html=False): """ TextField """ max_len = field.max_length or 16 * 1024 for validator in field.validators: if isinstance(validator, MaxLengthValidator): max_len = min(max_len, validator.limit_value) value = generate_lorem_ipsum(paragraphs, html=html) value = Truncator(value).chars(max_len, html=html) setattr(instance, field.name, value)