提供根据其内容的哈希值设置键的django模型。
django-roesti的Python项目详细描述
#django roesti
`django roesti`提供了一个'hashedmodel',一个django模型,其主键是其内容的
散列。当您需要通过数据库的标识引用数据时,这可以有效地使用数据库,同时最小化到
数据库的往返行程,或者经常遇到相同的数据,并且需要确保它在数据库中不复制它。BR/> BR/>散列是通过将值转换为Python不变类型而生成的,然后生成BR/>生成其腌制值的MD5哈希值。< BR/>< BR/>‘HashedModels’,支持对其他“HasHeMdMeX”的引用。
Br/> 'DjangoRoest'已经过测试。使用Python3.6和Django 1.9。
欢迎拉取请求。
\roesti?
a*rósti*是一种瑞士土豆煎饼,类似于土豆饼。了解了?
并添加到“installed廑apps”中:
`` python
installed廑apps=[
…
‘roesti',
]
````
使用示例
哈希是根据“hash廑fields”中指定的字段计算的。外键
应该对id值进行散列。
例如,给定这些模型:
`` python
从roesti导入hashedmodel
class testmodel(hashedmodel):
散列字段=['char_field_1','integer_field_1']
char_field_1=models.charfield(max_length=32)
integer_field_1=models.integerfield()
class testreferencesmodel(hashedmodel):
hash_fields=['test_model_1_id','test_model_2_id',,ForeignKey(TestModel)Br/TestModel 1=模型。ForeignKey(TestModel)
整数字段Field1=Model。整数字段():BR/>‘BR/>< BR/>您可以用“确保”BR/>函数创建新的或检索现有的模型实例。`请确保“接受词典或模型实例。
`` python
my models=testmodel.objects.sure([{
'字符字段1':'字段1值1',
'整型字段1':1
},{
'字符字段1':'字段1值2',
'整型字段1':2
},{
'字符字段1':'字段1值3',
'integer\u field'u 1':3
>
my\u reference models=testreferencemodelsmodel.objects.确保({
'test\u model'1':{
'char\u field'u 1':'field 1值1',
'integer\u field'u 1':1
},
'test'test\u model'u 2':'char\u field'char字段2':'field1值2',
>
'integer\u field'integer\u field'u 1值2':
'integer\u field:2
},
“整型字段”:3
}
````
例如,这实现了一个有序的项列表。
注意在“hash”字段中使用“items”表示“testorderedlist”:
``python
class testorderedlist(hashedmodel):
hash字段=(“name”,“items”)
name=models.textfield()
class testitemdetails(hashedmodel):
hash字段=(“text”,)
text=models.textfield()
相关的“name=”items')
order=models.integerfield()
details=models.foreignkey(testitemdetails)
instances=testorderedlist.objects.确保([{
“name”:“my list 1”,
“items”:[{
“order”:索引,
“details”:{
“text”:“1 item%d”%index
}
}对于范围(10)中的索引,{
‘名称’:‘我的列表2’,
‘项目’:[{
‘顺序’:索引,
‘详细信息’:{
‘文本’:‘2项目%d’,{
}
}对于范围(10)中的索引,{
‘名称’:‘我的列表3’,
'项目':[{
'或顺序:索引,
详细信息:{
文本:'3项%d'%index
}
}对于范围(10)
}中的索引,
````
还有一个“哈希列表”模型,用于管理哈希项的有序列表。
若要使用,请创建相应的“哈希模型”和映射表。请注意
如果需要将对列表的引用存储在“hasedModel”中,如上面的
示例中所示,则不应使用“hashedList”。
``python
class testitem(hashedModel):
哈希字段=(“text”,)
text=models.textfield(blank=true,null=true)
class testlisitem(hashedListitemModel):
item=模型。foreignkey(testitem)
items=[
testitem(text=”item%d'%index)
用于范围(10)内的索引
]
my_list=hashedlist.objects。确保列表(testitem,items)
```
`django roesti`提供了一个'hashedmodel',一个django模型,其主键是其内容的
散列。当您需要通过数据库的标识引用数据时,这可以有效地使用数据库,同时最小化到
数据库的往返行程,或者经常遇到相同的数据,并且需要确保它在数据库中不复制它。BR/> BR/>散列是通过将值转换为Python不变类型而生成的,然后生成BR/>生成其腌制值的MD5哈希值。< BR/>< BR/>‘HashedModels’,支持对其他“HasHeMdMeX”的引用。
Br/> 'DjangoRoest'已经过测试。使用Python3.6和Django 1.9。
欢迎拉取请求。
\roesti?
a*rósti*是一种瑞士土豆煎饼,类似于土豆饼。了解了?
并添加到“installed廑apps”中:
`` python
installed廑apps=[
…
‘roesti',
]
````
使用示例
哈希是根据“hash廑fields”中指定的字段计算的。外键
应该对id值进行散列。
例如,给定这些模型:
`` python
从roesti导入hashedmodel
class testmodel(hashedmodel):
散列字段=['char_field_1','integer_field_1']
char_field_1=models.charfield(max_length=32)
integer_field_1=models.integerfield()
class testreferencesmodel(hashedmodel):
hash_fields=['test_model_1_id','test_model_2_id',,ForeignKey(TestModel)Br/TestModel 1=模型。ForeignKey(TestModel)
整数字段Field1=Model。整数字段():BR/>‘BR/>< BR/>您可以用“确保”BR/>函数创建新的或检索现有的模型实例。`请确保“接受词典或模型实例。
`` python
my models=testmodel.objects.sure([{
'字符字段1':'字段1值1',
'整型字段1':1
},{
'字符字段1':'字段1值2',
'整型字段1':2
},{
'字符字段1':'字段1值3',
'integer\u field'u 1':3
>
my\u reference models=testreferencemodelsmodel.objects.确保({
'test\u model'1':{
'char\u field'u 1':'field 1值1',
'integer\u field'u 1':1
},
'test'test\u model'u 2':'char\u field'char字段2':'field1值2',
>
'integer\u field'integer\u field'u 1值2':
'integer\u field:2
},
“整型字段”:3
}
````
例如,这实现了一个有序的项列表。
注意在“hash”字段中使用“items”表示“testorderedlist”:
``python
class testorderedlist(hashedmodel):
hash字段=(“name”,“items”)
name=models.textfield()
class testitemdetails(hashedmodel):
hash字段=(“text”,)
text=models.textfield()
相关的“name=”items')
order=models.integerfield()
details=models.foreignkey(testitemdetails)
instances=testorderedlist.objects.确保([{
“name”:“my list 1”,
“items”:[{
“order”:索引,
“details”:{
“text”:“1 item%d”%index
}
}对于范围(10)中的索引,{
‘名称’:‘我的列表2’,
‘项目’:[{
‘顺序’:索引,
‘详细信息’:{
‘文本’:‘2项目%d’,{
}
}对于范围(10)中的索引,{
‘名称’:‘我的列表3’,
'项目':[{
'或顺序:索引,
详细信息:{
文本:'3项%d'%index
}
}对于范围(10)
}中的索引,
````
还有一个“哈希列表”模型,用于管理哈希项的有序列表。
若要使用,请创建相应的“哈希模型”和映射表。请注意
如果需要将对列表的引用存储在“hasedModel”中,如上面的
示例中所示,则不应使用“hashedList”。
``python
class testitem(hashedModel):
哈希字段=(“text”,)
text=models.textfield(blank=true,null=true)
class testlisitem(hashedListitemModel):
item=模型。foreignkey(testitem)
items=[
testitem(text=”item%d'%index)
用于范围(10)内的索引
]
my_list=hashedlist.objects。确保列表(testitem,items)
```