qs1 = TAB2.objects.filter( TAB1__id=1)
p = TAB2.objects.raw(
'''SELECT TAB2.option, Count(TAB1.id) AS num1
FROM TAB1 INNER JOIN TAB2 ON TAB1.Link = TAB2.id
GROUP BY TAB2.option
ORDER BY Count(TAB1.id) DESC;
''')
TAB2.objects.annotate(num1=Count('TAB2')).order_by('-num1')
p = TAB2.objects.raw(
'''SELECT TAB2.id, TAB2.option, COUNT(TAB1.id) AS num1
FROM TAB2
LEFT OUTER JOIN TAB1
ON ( TAB2.id = TAB1.Link )
GROUP BY TAB2.id, TAB2.option
ORDER BY num1 DESC;
''')
p = TAB2.objects.raw(
'''SELECT TAB2.option, Count(TAB1.id) AS CountObj
FROM TAB1 INNER JOIN TAB2 ON TAB1.Link = TAB2.id
GROUP BY TAB2.option
ORDER BY Count(TAB1.id) DESC;
''')
TAB2.objects.annotate(num_in_TAB2=Count('TAB2')).order_by('-num_in_TAB2')
<script type="text/javascript">
$(document).ready(function(){
$('#input_address').submit(function(){
$.ajax({
type: "POST",
url: "get_address",
data: "csrfmiddlewaretoken={{ csrf_token }}&address="+$("#address").val(),
success: function(html){
$("#box").html(html);
}
});
return false;
});
});
</script>