0

django models.py

class cdr(models.Model):
    id = models.AutoField(primary_key=True, unique=True, verbose_name='id',)
    disposition = models.CharField(max_length=45, default='')
    did = models.CharField(max_length=50, default='')

    def __unicode__(self):
        return u'%s' % self.id

    class Meta:
        ordering=['-calldate']
        db_table = 'cdr'

MySQL Query:

select id, did as diddst, count(did) as count, (select count(did) from cdr where disposition='NO ANSWER' and did=diddst) as countnoanswer from cdr where did in (79244576674, 79244576619) group by did;

result

+------+-------------+-------+---------------+
| id   | diddst      | count | countnoanswer |
+------+-------------+-------+---------------+
| 1011 | 79244576619 |   218 |            71 |
| 1756 | 79244576674 |  1528 |           654 |
+------+-------------+-------+---------------+

how to execute this subquery in Django orm? help me please Django guys!

1 Answer 1

1

You will have to do a raw query.

cdr.objects.raw('...')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.