Python django.contrib.postgres.fields 模块,HStoreField() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用django.contrib.postgres.fields.HStoreField()

项目:extractfacts    作者:oneroyalace    | 项目源码 | 文件源码
def from_field(cls, field):
        if POSTGRES_AVAILABLE:
            if isinstance(field, JSONField) or isinstance(field, HStoreField):
                return cls(verbose_name=title(field.verbose_name))
项目:extractfacts    作者:oneroyalace    | 项目源码 | 文件源码
def from_field(cls, field):
        if POSTGRES_AVAILABLE:
            if isinstance(field, JSONField) or isinstance(field, HStoreField):
                return cls(verbose_name=title(field.verbose_name))
项目:django_postgres_extensions    作者:primal100    | 项目源码 | 文件源码
def __init__(self, fields=(), keys=(), max_value_length=25, require_all_fields=False, **kwargs):
        super(HStoreField, self).__init__(**kwargs)
        self.fields = fields
        self.keys = keys
        self.max_value_length = max_value_length
        self.require_all_fields = require_all_fields
项目:django_postgres_extensions    作者:primal100    | 项目源码 | 文件源码
def formfield(self, **kwargs):
        if self.fields or self.keys:
            defaults = {
                'form_class': NestedFormField,
                'fields': self.fields,
                'keys': list(self.keys),
                'require_all_fields': self.require_all_fields,
                'max_value_length': self.max_value_length
            }
            defaults.update(kwargs)
        else:
            defaults = kwargs
        return super(HStoreField, self).formfield(**defaults)
项目:graphene-django    作者:graphql-python    | 项目源码 | 文件源码
def test_should_query_postgres_fields():
    from django.contrib.postgres.fields import IntegerRangeField, ArrayField, JSONField, HStoreField

    class Event(models.Model):
        ages = IntegerRangeField(help_text='The age ranges')
        data = JSONField(help_text='Data')
        store = HStoreField()
        tags = ArrayField(models.CharField(max_length=50))

    class EventType(DjangoObjectType):

        class Meta:
            model = Event

    class Query(graphene.ObjectType):
        event = graphene.Field(EventType)

        def resolve_event(self, info):
            return Event(
                ages=(0, 10),
                data={'angry_babies': True},
                store={'h': 'store'},
                tags=['child', 'angry', 'babies']
            )

    schema = graphene.Schema(query=Query)
    query = '''
        query myQuery {
          event {
            ages
            tags
            data
            store
          }
        }
    '''
    expected = {
        'event': {
            'ages': [0, 10],
            'tags': ['child', 'angry', 'babies'],
            'data': '{"angry_babies": true}',
            'store': '{"h": "store"}',
        },
    }
    result = schema.execute(query)
    assert not result.errors
    assert result.data == expected