Skip to content

Instantly share code, notes, and snippets.

@walison17
Last active June 24, 2019 14:40
Show Gist options
  • Save walison17/ee32185d4efd110638a0a575d8c0b355 to your computer and use it in GitHub Desktop.
Save walison17/ee32185d4efd110638a0a575d8c0b355 to your computer and use it in GitHub Desktop.
from django.db.models import Case, Value, When, F
from django.db.models.functions import Cast
result = (
Live
.objects
.annotate(
like_frequence=Case(
When(like__gt=0, then=Cast('unlike', models.DecimalField()) / F('like')),
default=Value(0),
output_field=models.DecimelField()
)
)
.filter(like_frequence__lt=0.2)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment