Q:

How to do this query using Django orm?

I have a Profile model and Complain model both are connected to the inbuilt User model.I have to do a query using both in which Profile model have residence. I want to have a count, that how many complains are made from a particular residence. I can do it using SQL but I didn't know how to do it using Django. 
SELECT users_profile.residence,count(user_id)from users_profile INNER JOIN chp_complain on(users_profile.user_id = chp_complain.complain_user_id)GROUP BY(user_id)

Complain Model:-
class Complain(models.Model):

    complain_user = models.ForeignKey(User, on_delete=models.CASCADE)
    complain_department=models.CharField(max_length=100)
    complain_subject = models.CharField(max_length = 100,help_text =  "Enter the complain subject")
    department_head=models.CharField(max_length=100)
    recepient=models.CharField(max_length=100)
    complain_description=models.TextField(max_length=2000)
    date_posted = models.DateTimeField(default = timezone.now)
    NOT_VISITED = 'NV'
    VISITED = 'V'
    INPROCESS = 'IP'
    COMPLETED = 'C'
    status = (
        (NOT_VISITED, 'NV'),
        (VISITED, 'V'),
        (INPROCESS, 'IP'),
        (COMPLETED, 'C'),)
    status=models.CharField(max_length=2,choices=status,)

Profile Model:-
class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    UID =models.CharField(max_length=30,default = "000",help_text = "'Staff's fill their STAFF ID and student's fill their ROLL NO " )
    MALE = 'M'
    FEMALE = 'F'
    Gender=((MALE, 'Male'),(FEMALE, 'Female'),)
    Gender=models.CharField(max_length=6,choices=Gender,default=MALE,)
    FIRST = '1st'
    SECOND = '2nd'
    THIRD = '3rd'
    FOURTH = '4th'
    NGH = 'NGH'
    NON_HOSTELER = 'Non_hosteler'
    TEACHER_QUARTER = 'Teacher_quarter'
    residence = ((FIRST, 'First'),(SECOND, 'Second'),(THIRD, 'Third'),(FOURTH, 'Fourth'),(NGH,'NGH'),(NON_HOSTELER, 'Non_hosteler'),(TEACHER_QUARTER,'Teacher_quarter'))
    residence = models.CharField(max_length=20,choices=residence,default=FIRST,)
    room_no=models.CharField(max_length=10,default = "000")

A:

I want to have a count, that how many complains are made from a particular residence you can write:
Complain.objects.values('complain_user__profile__residence').annotate(complains_count=Count('id'))

In your SQL query:
SELECT users_profile.residence,count(user_id)from users_profile INNER JOIN chp_complain on(users_profile.user_id = chp_complain.complain_user_id)GROUP BY(user_id)

You calculate how many users filed complaints from a particular residence. It can be calculated as follows:
User.objects.values('profile__residence').annotate(Count('id'))

