[문서]classHStoreField(Field):empty_strings_allowed=Falsedescription=_('Map of strings to strings/nulls')default_error_messages={'not_a_string':_('The value of "%(key)s" is not a string or null.'),}defdb_type(self,connection):return'hstore'defget_transform(self,name):transform=super().get_transform(name)iftransform:returntransformreturnKeyTransformFactory(name)defvalidate(self,value,model_instance):super().validate(value,model_instance)forkey,valinvalue.items():ifnotisinstance(val,str)andvalisnotNone:raiseexceptions.ValidationError(self.error_messages['not_a_string'],code='not_a_string',params={'key':key},)defto_python(self,value):ifisinstance(value,str):value=json.loads(value)returnvaluedefvalue_to_string(self,obj):returnjson.dumps(self.value_from_object(obj))defformfield(self,**kwargs):defaults={'form_class':forms.HStoreField,}defaults.update(kwargs)returnsuper().formfield(**defaults)defget_prep_value(self,value):value=super().get_prep_value(value)ifisinstance(value,dict):prep_value={}forkey,valinvalue.items():key=str(key)ifvalisnotNone:val=str(val)prep_value[key]=valvalue=prep_valueifisinstance(value,list):value=[str(item)foriteminvalue]