python - Number order ignores decimals in Django Postgres -
building locally in sqlite. app has numbers prices of object. in sqlite able sort prices regulary (ex: $914, $799, $120, $95, 9.00, 7.50.)
after pushing app postgres numbers come such: 95, 914, 9.00, 799, 7.50, 120.
i'm looking order them price high low , low high in postgres. doing wrong?
model field:
price = models.decimalfield(max_digits=8, decimal_places=2, null=true) url:
url(r'^browse/price_desc/$', 'collection.views.price_desc', name="pricehigh") view:
def price_desc(request): items = item.objects.all.order_by('-price') return render(request, 'index.html', { 'items' : items, })
first off, decimalfield based on python decimal.
according this answer on question decimal values, way postgres store decimals packed bcd string. way order show reflects order of sorted strings, not numbers.
not sure how django implements sorting of decimalfield, assuming sorting string.
while decimalfield seems appropriate use-case, may want switch floatfield in order sorting looking for.
Comments
Post a Comment