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

  • SEARCH
  • Home
  • 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 663199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:27:48+00:00 2026-05-13T23:27:48+00:00

I am creating small django application which holds some few questions (and answers for

  • 0

I am creating small django application which holds some few questions (and answers for them)

What I want to do is to show user random question, but only from those which was not solved by him yet. I wonder how to do this.

For now, I defined user profile model this way:

class UserProfile(models.Model):
    rank = models.IntegerField(default = 1)
    solvedQ = models.ManyToManyField(Question)
    user = models.ForeignKey(User, unique=True)

So solved problems are added this way:

if user.is_authenticated():
    profile = user.get_profile()
    profile.rank += 1
    profile.solvedQ.add(Question.objects.get(id=id))

Now if the view must show random question, but not from already solved list…

Is there a good way to intersect Questions and solvedQuestions…. so question is chosen from the unsolved list?

  • 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-13T23:27:48+00:00Added an answer on May 13, 2026 at 11:27 pm

    ManyToMany relationships are automatically symmetrical in Django … http://docs.djangoproject.com/en/1.1/topics/db/models/#many-to-many-relationships

    Run a query from the Question model

    Without seeing your Quesion model, I assume it will end up looking something like this:

    possible_questions = Questions.objects.filter(~(UserProfile=profile))
    

    I believe that query will give you the all results where the User related to the Question does not match the current user. I am not very familiar with running “not” queries. A quick lookup told me that the ‘~’ will do it but you should double-check.

    Then, you can just grab a random one from the returned queryset.

    ** edit **

    Looks like you can grab the random right in the query by doing something like:

    possible_questions = Questions.objects.filter(~(UserProfile=profile)).order_by('?')
    

    Then just use the first one returned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a small deb package to install a few files. Some of them
I am creating a small application which will perform say 4 different, time consuming
I'm creating a small program which consists of a few source files on my
I am creating a small website that allows a user to browse some of
I'm creating a small application from which users can send mails, appointments and to-do
I'm creating a small code plugin which allows you to do some things with
I am creating a small winforms application for distribution to a few people. I
I am creating a small fun application to play some mp3 files into a
I am creating a small commercial web project running Apache/WSGI/Django/MySQL. I have a development
I am creating a small (for now) stored procedure to insert some data. When

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.