django - How do I compare a CombinedResponse object value with an int? -


i'm trying annotate query percentage repsents how "complete" business logic is. don't want percentage go on 100%. have in query:

.annotate(completion=max(100, count('id')/f('something_tricky') ) 

the issue count/f combinedexpression, unorderable, can't used in max. won't let me cast int either:

int() argument must string, bytes-like object or number, not 'combinedexpression'

or string.

how completion value int out of query?

you must use database functions annotations, in case greatest function.

from django.db.models import value django.db.models.functions import greatest  .annotate(completion=greatest(value(100), count('id')/f('something_tricky') ) 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -