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 7739861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:37:45+00:00 2026-06-01T08:37:45+00:00

I am using the following models in my django application and want to query

  • 0

I am using the following models in my django application and want to query across multiple fields. I looked around different places but couldnt find out what i exactly need.

class Attempt(models.Model, object):
    '''Creates an Attempt Entity which is a subclass of models.Model class'''
    attemptID_f = models.AutoField(primary_key=True)
    questionID_f = models.ForeignKey(Question, verbose_name="Question", null=False)
    userID_f = models.ForeignKey(User, verbose_name="User ID", null=False)
    solution_f = models.TextField("Solution uploaded by the User", null=False)
    errorReportID_f = models.ForeignKey(ErrorReport,verbose_name="Error Report for the Solution", null=True)
    status_f = models.BooleanField("Status of attempt - true = right, false = wrong", blank=True, default=False)
    timeOfSubmission_f = models.DateTimeField("Time of Submission", null=False)
    compilerVersion_f = models.ForeignKey(CompilerVersion, verbose_name = "Compiler version of the Attempt",null=False)

class Question(models.Model, object):
    '''Creates the entity question 
    which is a subclass of models.Model'''
    questionID_f = models.AutoField(primary_key=True)
    questionText_f = models.TextField("Problem Statement", null=False)
    questionTitle_f = models.CharField("Problem Title", max_length = 50, null = False) 
    level_f = models.ForeignKey(Level, verbose_name="Question Level", null=False)
    type_f = models.ForeignKey(Type, verbose_name="Type of Question", null=False)
    timeLimit_f = models.FloatField("Time Limit for Question",null=False)

class Type(models.Model):
    '''Creates the entity Type which is a subclass of models.Model class'''
    typeID_f = models.AutoField(primary_key=True)
    typeName_f = models.CharField("Type Name" , max_length = 30 , null = False)

typesm = Attempt.objects.filter(userID_f = request.user).values('attempt__questionID_f__type_f__typeID_f')

Is attempt__questionID_f__type_f__typeID_f a valid arguement if I want to reference the typeID_f field of type MODEL, which is referenced by type_f field of Question Model, which is referenced by questionID_f field of Attempt Model ?

Any help would be appreciated.

Thanks,

Pankaj.

  • 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-06-01T08:37:46+00:00Added an answer on June 1, 2026 at 8:37 am

    Should be:

    typesm = Attempt.objects.filter(userID_f = request.user).values('questionID_f__type_f__typeID_f')
    

    I’m not sure why you put the attempt__ prefix there when you are querying the Attempt model.

    See: Lookups that span relationships

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

Sidebar

Related Questions

In a django application I have the following model: class Appointment(models.Model): #some other fields
I'm trying to add custom fields to an InlineFormset using the following code, but
I'm using Django-nonrel on Google App Engine and have the following models (they are
hi i am using the following models to build a database from django.db import
I'm trying to create my first application using Django. I'm using the following code
Trying to create a Django app based off the tutorial but using a different
Using the following related models (one blog entry can have multiple revisions): class BlogEntryRevision(models.Model):
I am using Rails 3.2. I have following models: Blog Comment User class Blog
I'm developing application using backbone.js & jquery. I have following code in model: runReport:
I am working on an application using Google application engine and Django. I am

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.