On 7/29/07, Tim Chase <[EMAIL PROTECTED]> wrote: > > > currently I using filter to find closest match: > > step=100 > > w=2000 # get it from forms. > > value=pricelist.pricelisttable_set.filter(width__gte=w-step,width__lte=w+step)[0] > > > > The problem is that "step" is different for different tables so > > sometimes getting more values or none. > > > > What would be the best way to find the closest match? > > I have no idea what the Excel logic (or lack there of) may or may > not have been. Without Excel on my Linux box, it's hard to test, > and even if I did have Excel, there was no data against which to > test and see what the above formula should have done. :)
The same formula work on OpenOffice or Gnumeric on my linux box :) ( running Excel on wine ) The whole idea to find the value in DB which is closest to to value which we give at request. let say we have a table: width, heght1, heugth2........ 100, 210, 310, ... 200, 250, 280, ... 350, 260, 290, ... 520, 420, 460, ... ...... Now we'geot some number let say width=240 so the closest match in that case will be 200. In pure sql we can do : "select min(abs(width-150)) from quote_pricelisttable where name_id = 1 and width >= 240-150 and width <=240+150;" How to make it work properly from django ORM? -- -- Michael --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

