Django                
            HStoreField로 문자열을 문자열에 매핑하기 - PostgreSQL 특정 필드
        
        
            
    수색…
통사론
- FooModel.objects.filter (field_name__key_name = '쿼리 할 값')
HStoreField 설정
 먼저 HStoreField 작동하도록 설정해야합니다. 
-  django.contrib.postgres가`INSTALLED_APPS '에 있는지 확인하십시오
-  마이그레이션에 HStoreExtension을 추가하십시오.CreateModel또는AddField마이그레이션 전에HStoreExtension을 두는 것을 잊지AddField.
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 를 초기화하는 데 필요한 매개 변수가 없습니다. 
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()
새 모델 인스턴스 만들기
 네이티브 파이썬 사전을 전달 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')
포함 사용
 키워드 인수로 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