Skip to content

Instantly share code, notes, and snippets.

@walison17
Created December 14, 2019 17:29
Show Gist options
  • Save walison17/56d8b9389a3ee918e97a0851c727e5ac to your computer and use it in GitHub Desktop.
Save walison17/56d8b9389a3ee918e97a0851c727e5ac to your computer and use it in GitHub Desktop.
from django.db import models
q = (
Lancamento
.objects
.annotate(
val=models.Case(
When(account_from=8, then=models.F('valor') * -1),
default_value=models.F('valor'),
output_field=models.DecimalField()
)
)
.filter(
models.Q(account_to=8) | models.Q(account_from=8)
)
.values('account_from', 'account_to', 'val')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment