Django                
            HStoreField  - 文字列への文字列のマッピング -  PostgreSQL固有のフィールド
        
        
            
    サーチ…
構文
- FooModel.objects.filter(field_name__key_name = '照会する値')
HStoreFieldのセットアップ
まず、 HStoreField動作させるためにセットアップを行う必要があります。 
-  django.contrib.postgresがあなたの `INSTALLED_APPS 'にあることを確認してください
- 移行にHStoreExtensionを追加します。CreateModelまたはAddField移行の前にHStoreExtensionを配置することを忘れないでください。
from django.contrib.postgres.operations import HStoreExtension
from django.db import migrations
class FooMigration(migrations.Migration):
    # put your other migration stuff here
    operations = [
        HStoreExtension(),
        ...
    ]
モデルにHStoreFieldを追加する
->注意:この例ではまずHStoreFieldを設定してHStoreField。 (上記)
 HStoreFieldを初期化するためのパラメータは必要ありません。 
from django.contrib.postgres.fields import HStoreField
from django.db import models
    
class Catalog(models.model):
    name = models.CharField(max_length=200)
    titles_to_authors = HStoreField()
新しいモデルインスタンスを作成する
ネイティブのPython辞書に文字列をマッピングしてcreate()渡しcreate() 。 
Catalog.objects.create(name='Library of Congress', titles_to_authors={
    'Using HStoreField with Django': 'CrazyPython and la communidad',
    'Flabbergeists and thingamajigs': 'La Artista Fooista',
    'Pro Git': 'Scott Chacon and Ben Straub',
})
キー参照の実行
Catalog.objects.filter(titles__Pro_Git='Scott Chacon and Ben Straub')
containsを使う
 dictオブジェクトをキーワード引数としてfield_name__containsます。 
Catalog.objects.filter(titles__contains={
        'Pro Git': 'Scott Chacon and Ben Straub'})
Modified text is an extract of the original Stack Overflow Documentation
        ライセンスを受けた CC BY-SA 3.0
        所属していない Stack Overflow