當前位置: 首頁>>代碼示例>>Python>>正文


Python fields.CharField方法代碼示例

本文整理匯總了Python中django.db.models.fields.CharField方法的典型用法代碼示例。如果您正苦於以下問題:Python fields.CharField方法的具體用法?Python fields.CharField怎麽用?Python fields.CharField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.db.models.fields的用法示例。


在下文中一共展示了fields.CharField方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_django_field_map

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import CharField [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),
        ] 
開發者ID:danielecook,項目名稱:Quiver-alfred,代碼行數:21,代碼來源:djpeewee.py

示例2: test_field_rename_inside_atomic_block

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import CharField [as 別名]
def test_field_rename_inside_atomic_block(self):
        """
        NotImplementedError is raised when a model field rename is attempted
        inside an atomic block.
        """
        new_field = CharField(max_length=255, unique=True)
        new_field.set_attributes_from_name('renamed')
        msg = (
            "Renaming the 'backends_author'.'name' column while in a "
            "transaction is not supported on SQLite because it would break "
            "referential integrity. Try adding `atomic = False` to the "
            "Migration class."
        )
        with self.assertRaisesMessage(NotSupportedError, msg):
            with connection.schema_editor(atomic=True) as editor:
                editor.alter_field(Author, Author._meta.get_field('name'), new_field) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:tests.py

示例3: test_field_rename_inside_atomic_block

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import CharField [as 別名]
def test_field_rename_inside_atomic_block(self):
        """
        NotImplementedError is raised when a model field rename is attempted
        inside an atomic block.
        """
        new_field = CharField(max_length=255, unique=True)
        new_field.set_attributes_from_name('renamed')
        msg = (
            "Renaming the 'backends_author'.'name' column while in a "
            "transaction is not supported on SQLite < 3.26 because it would "
            "break referential integrity. Try adding `atomic = False` to the "
            "Migration class."
        )
        with self.assertRaisesMessage(NotSupportedError, msg):
            with connection.schema_editor(atomic=True) as editor:
                editor.alter_field(Author, Author._meta.get_field('name'), new_field) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:tests.py

示例4: build_schema_from_model

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import CharField [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) 
開發者ID:ebmdatalab,項目名稱:openprescribing,代碼行數:24,代碼來源:bigquery.py

示例5: _build_search_filter

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import CharField [as 別名]
def _build_search_filter(cls, field_name):
    if field_name == "bnf_code":
        return _build_search_filter_bnf_code_prefox()

    field = cls._meta.get_field(field_name)
    builder = {
        ForeignKey: _build_search_filter_fk,
        ManyToOneRel: _build_search_filter_rev_fk,
        OneToOneRel: _build_search_filter_rev_fk,
        fields.CharField: _build_search_filter_char,
        fields.DateField: _build_search_filter_date,
        fields.BooleanField: _build_search_filter_boolean,
        fields.DecimalField: _build_search_filter_decimal,
    }[type(field)]
    search_filter = builder(field)
    search_filter["id"] = field_name
    return search_filter 
開發者ID:ebmdatalab,項目名稱:openprescribing,代碼行數:19,代碼來源:build_search_filters.py

示例6: get_comparison_class

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import CharField [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 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:32,代碼來源:edit_handlers.py

示例7: as_oracle

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import CharField [as 別名]
def as_oracle(self, compiler, connection):
        # we can't mix TextField (NCLOB) and CharField (NVARCHAR), so convert
        # all fields to NCLOB when we expect NCLOB
        if self.output_field.get_internal_type() == 'TextField':
            class ToNCLOB(Func):
                function = 'TO_NCLOB'

            expressions = [
                ToNCLOB(expression) for expression in self.get_source_expressions()]
            clone = self.copy()
            clone.set_source_expressions(expressions)
            return super(Coalesce, clone).as_sql(compiler, connection)
        return self.as_sql(compiler, connection) 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:15,代碼來源:base.py

示例8: _raw_sql

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import CharField [as 別名]
def _raw_sql(self, values: List[Tuple[Union[str, int], Union[str, int]]]) -> str:
        """Prepare SQL statement consisting of a sequence of WHEN .. THEN statements."""
        if isinstance(self.model._meta.pk, CharField):
            when_clauses = " ".join(
                [self._when("'{}'".format(x), y) for (x, y) in values]
            )
        else:
            when_clauses = " ".join([self._when(x, y) for (x, y) in values])
        table_name = self.model._meta.db_table
        primary_key = self.model._meta.pk.column
        return 'SELECT CASE {}."{}" {} ELSE 0 END'.format(
            table_name, primary_key, when_clauses
        ) 
開發者ID:yunojuno,項目名稱:elasticsearch-django,代碼行數:15,代碼來源:models.py

示例9: lookups

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import CharField [as 別名]
def lookups(self, request, model_admin):
        queryset = model_admin.get_queryset(request).distinct() \
            .annotate(
                _name_provider=Concat(
                    F('plan__name'), Value(' ('), F('plan__provider__name'), Value(')'),
                    output_field=fields.CharField()
                ),
        ) \
            .values_list('id', '_name_provider') \
            .distinct()

        return list(queryset) 
開發者ID:silverapp,項目名稱:silver,代碼行數:14,代碼來源:admin.py

示例10: get_search_results

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import CharField [as 別名]
def get_search_results(self, request, queryset, search_term):
        if '-' in search_term and search_term[-1].isdigit():
            return queryset \
                .annotate(_series_number=Concat(F('series'), Value('-'), F('number'),
                                                output_field=fields.CharField())) \
                .filter(_series_number=search_term), True

        return super(BillingDocumentAdmin, self).get_search_results(request, queryset, search_term) 
開發者ID:silverapp,項目名稱:silver,代碼行數:10,代碼來源:admin.py

示例11: build_column_filter

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import CharField [as 別名]
def build_column_filter(column_name, column_obj, column_spec, search_value):
    search_filter = None

    # if type(column_obj.model_field) == fields.CharField:
    #     # do something special with this field

    choices = column_spec['choices']
    if column_obj.has_choices_available:

        if choices:
            # Since we're using choices (we provided a select box)
            # just use the selected key
            values = [search_value, ]
        else:
            values = column_obj.search_in_choices(search_value)

        search_filter = Q(**{column_obj.name + '__in': values})

    elif isinstance(column_obj.model_field, (models.DateTimeField, models.DateField)):
        try:
            parsed_date = parse_date(search_value)
            date_range = [parsed_date.isoformat(), parsed_date.isoformat()]
            query_param_name = column_obj.get_field_search_path()
            if isinstance(column_obj.model_field, models.DateTimeField):
                search_filter = Q(**{query_param_name + '__date__range': date_range})
            else:
                search_filter = Q(**{query_param_name + '__range': date_range})
        except ValueError:
            pass
    else:
        query_param_name = column_obj.get_field_search_path()
        #search_filters |= Q(**{query_param_name + '__istartswith': search_value})
        search_filter = Q(**{query_param_name + '__icontains': search_value})

    return search_filter 
開發者ID:morlandi,項目名稱:django-datatables-view,代碼行數:37,代碼來源:filters.py

示例12: __init__

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import CharField [as 別名]
def __init__(self, *args, **kwargs):
        # Local import so the languages aren't loaded unless they are needed.
        from .languages import LANGUAGES

        kwargs.setdefault('max_length', 3)
        kwargs.setdefault('choices', LANGUAGES)
        super(CharField, self).__init__(*args, **kwargs) 
開發者ID:audiolion,項目名稱:django-language-field,代碼行數:9,代碼來源:fields.py

示例13: test_get_data_field

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import CharField [as 別名]
def test_get_data_field(self):
        field_info = self._details(Person, Person._meta.get_field('data_abstract'))
        self.assertEqual(field_info[1:], (BasePerson, True, False))
        self.assertIsInstance(field_info[0], CharField) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:tests.py

示例14: _build_lookup_key

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import CharField [as 別名]
def _build_lookup_key(cls, field_name, operator):
    field = cls._meta.get_field(field_name)
    builder = {
        ForeignKey: _build_lookup_fk,
        ManyToOneRel: _build_lookup_rev_fk,
        OneToOneRel: _build_lookup_rev_fk,
        fields.CharField: _build_lookup_char,
        fields.DateField: _build_lookup_date,
        fields.BooleanField: _build_lookup_boolean,
        fields.DecimalField: _build_lookup_decimal,
    }[type(field)]
    return builder(cls, field_name, operator) 
開發者ID:ebmdatalab,項目名稱:openprescribing,代碼行數:14,代碼來源:build_search_query.py

示例15: get_field_nullability

# 需要導入模塊: from django.db.models import fields [as 別名]
# 或者: from django.db.models.fields import CharField [as 別名]
def get_field_nullability(self, field: Union[Field, ForeignObjectRel], method: Optional[str]) -> bool:
        nullable = field.null
        if not nullable and isinstance(field, CharField) and field.blank:
            return True
        if method == '__init__':
            if ((isinstance(field, Field) and field.primary_key)
                    or isinstance(field, ForeignKey)):
                return True
        if method == 'create':
            if isinstance(field, AutoField):
                return True
        if isinstance(field, Field) and field.has_default():
            return True
        return nullable 
開發者ID:typeddjango,項目名稱:django-stubs,代碼行數:16,代碼來源:context.py


注:本文中的django.db.models.fields.CharField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。