Python django.db.models.fields.TextField() Examples

The following are 5 code examples of django.db.models.fields.TextField(). 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 vote down vote up
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: bigquery.py    From openprescribing with MIT License 6 votes vote down vote up
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 #3
Source File: application_tags.py    From mitoc-trips with GNU General Public License v3.0 6 votes vote down vote up
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} 
Example #4
Source File: edit_handlers.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #5
Source File: forms.py    From mitoc-trips with GNU General Public License v3.0 5 votes vote down vote up
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)