Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4611044
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:12:53+00:00 2026-05-22T01:12:53+00:00

I have 3 models in django: class Movie(models.Model): mid = models.IntegerField(primary_key = True) name

  • 0

I have 3 models in django:

class Movie(models.Model):
    mid = models.IntegerField(primary_key = True)
    name = models.CharField(max_length = 100)

class User(models.Model):
    username = models.CharField(max_length=128, null=True)
    uid = models.CharField(max_length=100)
    movie = models.ManyToManyField(Movie, through = "Vote")

class Vote(models.Model):
    movie = models.ForeignKey(Movie)
    user = models.ForeignKey(User)
    rating = models.IntegerField()

here rating = 0/1, 0 means dislike, 1 means like
i want to make some queries using filters:

  1. find out all movies that a current user likes. For that i use this following 2 queries, but none of them work. In both cases it gives erroneous results

    ans = Movie.objects.filter(vote__user = self).filter(vote__rating = 1)

    ans = Movie.objects.filter(user__uid = self.uid).filter(vote__rating = 1)

  2. I have a list of users in an array ids. I want to find out how many users from this list like a particular movie?
    i tried this, but this is also incorrect:

    ret = User.objects.filter(uid__in = ids).filter(vote__movie = mov).filter(vote__rating = 1)

can somebody please help me with these 2 queries?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:12:54+00:00Added an answer on May 22, 2026 at 1:12 am

    I’d also suggest letting django assign the model’s id’s but if you are using a legacy database or for some other reason need to assign the id’s you can query like so:

    1. # uid is some uid
      user = User.objects.get(uid=uid)
      likes = Movie.objects.filter(vote__user=user, vote__rating=1)
      

      or

      likes = Movie.objects.filter(vote__user__uid=some_uid, vote__rating=1)
      
    2. count of people in the list of users who like a specific movie:

      >>> uids = ['1','2','3']
      >>> # if mov is a Movie instance
      >>> votes = Vote.objects.filter(user__uid__in=uids, movie=mov, rating=1)
      >>> print votes.query
      SELECT "so1_vote"."id", "so1_vote"."movie_id", "so1_vote"."user_id", "so1_vote"."rating" FROM "so1_vote" INNER JOIN "so1_user" ON ("so1_vote"."user_id" = "so1_user"."id") WHERE ("so1_user"."uid" IN (1, 2, 3) AND "so1_vote"."movie_id" = 1  AND "so1_vote"."rating" = 1 )
      >>> # if mov is a mid for a movie
      >>> # get movie instance by using Movie.objects.get(mid=mov)
      >>> # or query:
      >>> # votes = Vote.objects.filter(user__uid__in=uids, movie__mid=mov, rating=1)
      >>> likes_count = votes.count()
      >>> print likes_count
      0
      

      combined:

      likes_count = Votes.objects.filter(user__uid__in=uids, movie=mov, rating=1).count()
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Django and Flex code: Django class Author(models.Model): name = models.CharField(max_length=30)
In Django I have theses models: class Artist(models.Model): name = models.CharField(max_length=128) born_place = models.ForeignKey(???)
I have this models in Django class Country(models.Model): name = models.CharField(max_length=80) class Person(models.Model): first_name
I have models (simplified example): class Group(models.Model): name = models.CharField(max_length = 32) class Person(models.Model):
I have 3 django models (simplified for this example): class Fighter (models.Model): name =
(Django 1.x, Python 2.6.x) I have models to the tune of: class Animal(models.Model): pass
I have the following model in Django: class Bout (models.Model): fighter_1 = models.ForeignKey(Fighter, related_name=bout_fighter_1)
I have the following multi-table inheritance situation: from django.db import Models class Partner(models.Model): #
Lets say, I have following models in my Django app. class EventGroup name =
I have a django model: class Book(models.Model): [..] and I want to have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.