V
V
Val1n0r2019-09-18 11:04:07
Django
Val1n0r, 2019-09-18 11:04:07

Django ORM - how to express sql query?

Actually the question is how to express such a mysql expression

SELECT lvl FROM userlevel WHERE lvlxp - UserXp <= 0

using django orm?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2019-09-18
@devildayne

Alternatively using the F() operator and annotations :

Userlevel.objects.annotate(difference=F('lvlxp') - F('UserXp'))\
    .filter(difference__lte=0).values_list('lvl', flat=True)

L
Larisa .•º, 2019-09-18
@barolina

https://docs.djangoproject.com/en/2.2/topics/db/ag...
Userlevel .objects.filter(lvlxp__lte=UserXp)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question