I did it in your way, it certainly works.

But I feel this is a little ugly. My query is way more complicated
that the example here so I had to do if a lot.

On Sep 3, 8:29 am, Justin <jlmurph...@gmail.com> wrote:
> Off the top of my head, you could do something like this:
>
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to