我正在使用Django-hstore库,并且有很好的管理小部件。subject表存储计算机的组件,如下所示:
class Component(models.Model):
name = models.CharField(max_length=64)
purchase_date = models.DateField(blank=True, null=True)
product_page = models.URLField(blank=True, help_text='url to pruduct page')
<...>
data = hstore.DictionaryField(blank=True)
def load_cpu_data(self):
if self.product_page:
info = cpu_data(self.product_page)
if info: # info is a SortedDict with proper order
for key, value in info.items():
self.data[key] = value
self.save()接下来,我从cpu-world.com获取必要的CPU数据,我在admin中有以下内联数据:

看起来不错,但按字母顺序排序,而不是逻辑排序,按照load_cpu_data模型方法将数据加载到数据库中的顺序。正确排序的示例,如在cpu-world上:
Family
Model number
Frequency
Socket
Microarchitecture
Processor core
Manufacturing process
Data width
The number of CPU cores
The number of threads
Integrated graphics
Thermal Design Power有没有技巧,或者技巧,或者什么东西可以帮助我以所需的顺序显示数据?例如,我发现了python OrderedDict数据类型,它与我需要的数据类型相似。但显然是hstore内部结构混乱的数据顺序。
发布于 2017-10-05 22:15:39
根据the hstore docs, hstore itself is not ordered的说法
配对的顺序并不重要(并且可能不会在输出时重现)。忽略成对之间或=>符号周围的空格。包含空格、逗号、=s或>s的双引号键和值。要在键或值中包括双引号或反斜杠,请使用反斜杠对其进行转义。
https://stackoverflow.com/questions/39849753
复制相似问题