I try to implement a simple select with an order_by aggregation in pony orm:
So, I tried to ways: The first way raise a error message:
sel = select((f.Name, f.id) for f in Firma).order_by(Firma.Name)
In this way, I get the error message from python: "NotImplementedError: Ordering by attributes is limited to queries which return simple list of objects. Try use other forms of ordering (by tuple element numbers or by full-blown lambda expr)"
The second way, were the selection in order works fine but the inserting in my dictionary destroy the disered selection order
for f in Firma.select(lambda f: f.Name) \
.order_by((Firma.Name)):
dic[f.Name] = f.id
print ("=== f.Name", f.Name)
dic[f.Name] = f.id
print(" === dic[f.Name]", dic[f.Name])
The result is the following:
=== f.Name A
=== dic[f.Name] 10
=== f.Name B
=== dic[f.Name] 11
=== f.Name C
=== dic[f.Name] 12
=== f.Name Neckermann
=== dic[f.Name] 7
=== f.Name Otto
=== dic[f.Name] 6
=== f.Name Quelle
=== dic[f.Name] 3
=== f.Name Testfirma
=== dic[f.Name] 9
=== f.Name The Pearlfactory
=== dic[f.Name] 8
But the dictionary is:
dic {'Testfirma': 9, 'Quelle': 3, 'C': 12, 'The Pearlfactory': 8, 'B': 11, 'Otto': 6, 'A': 10, 'Neckermann': 7}
Now the questions: How I can use the first way of order_by aggregation whithout this error message. Or, How I can put the values of firm id and firm name in my dictionary in the sorted soccesion
I hope someone can understand my terrible english ;)
Greetings
niesel