1

I'm use Django-hstore library, and there is pretty admin widget. The subject table store computer's components, something like this:

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()

Next, I get data from cpu-world.com about necessary CPU and I have following inline data in admin:

enter image description here

Look great, but sorting alphabetically instead logical, in order of loading data into database in load_cpu_data model method. Example of proper order, like on 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

Is there technique, or trick, or something to help me show data in desired sequence? For example, I found python OrderedDict data type, which similar to what I need. But apparently hstore inner structure mess data order.

swasher
  • 368
  • 4
  • 17

1 Answers1

0

according to the hstore docs, hstore itself is not ordered:

The order of the pairs is not significant (and may not be reproduced on output). Whitespace between pairs or around the => sign is ignored. Double-quote keys and values that include whitespace, commas, =s or >s. To include a double quote or a backslash in a key or value, escape it with a backslash.

Jiaaro
  • 74,485
  • 42
  • 169
  • 190