我有一个问题,然后当我试图从查询集获得特定的值它给我以字母顺序。例子:
account_data = Account.objects.all()
[<Account: Merchant: ID: 267 (google@gmail.com), Currency: RUB, Brand: Brand NEWW (google@gmail.com)>,
<Account: Merchant: ID: 265 (goole@gmail.com), Currency: EUR, Brand: Brand new (google@gmail.com)>,
<Account: Merchant: ID: 264 (google@gmail.com), Currency: USD, Brand: Brand new2 (google@gmail.com)>,
<Account: Merchant: ID: 266 (google@gmail.com), Currency: TRY, Brand: Brand new 3 (google@gmail.com)>,
<Account: Merchant: ID: 269 (google@gmail.com), Currency: BGN, Brand: Brand new 4 (google@gmail.com)>]
currency = ', '.join(sorted(list(account_data.values_list('currency__code', flat=True))))
Out[66]: 'BGN, EUR, RUB, TRY, USD'
这个问题出现在所有值,需要得到货币连接到一个特定的帐户,而不是随机或字母顺序。
期望结果:RUB, EUR, USD, TRY, BGN
使用oder_by("pk")然后你会得到创建的顺序