Django group by Count함수, order by(정렬)
2021. 4. 3. 14:00ㆍ파이썬/Django
쿼리
select char,count(char) total from Trained_Box
where status='registered'
group by char
order by total desc
결과
def dashboard(request) :
template = 'ocr/dashboard.html'
chars = Trained_Box.objects.filter(status='registered').values('char').annotate(total=Count('char')).order_by('-total')
print(chars)
results = {
'results' : chars
}
print(results)
return render(request, template, results)
'파이썬 > Django' 카테고리의 다른 글
Django filter count() (0) | 2021.04.04 |
---|---|
django.db.utils.OperationalError: user-defined function raised exception (0) | 2021.04.04 |
Django context must be a dict rather than QuerySet. (0) | 2021.04.03 |
Django view에 template 적용한 화면 추가 (0) | 2021.03.28 |
Django admin 위치 (0) | 2021.03.27 |