【发布时间】:2017-02-12 11:15:48
【问题描述】:
我正在使用 Django-hstore 库,并且有漂亮的管理小部件。主题表存储计算机的组件,如下所示:
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 的数据,并且我在管理员中有以下内联数据:
看起来不错,但按字母顺序排序而不是逻辑排序,以便在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内部结构乱七八糟的数据顺序。
【问题讨论】:
标签: python django django-admin hstore django-hstore