import math
import django.db.models.Q
jeff_abs = math.fabs(jeff.balance) #get the absolute value of jeff's
balance
Account.objects.get(Q(balance__gt=jeff_abs) | Q(balance__lt=(jeff_abs
* -1)))
This way you pick up all positive balances greater than jeff's
absolute balance and all negative balances less than jeff's absolute
balance. This avoids adding a field to your model like 'balance_abs',
which would be just a calculation anyways.
I don't know if this is the cleanest way to do it, but let me know if
it works...
-Justin
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment