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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:09:14+00:00 2026-05-26T04:09:14+00:00

class InspectionQuestion(models.Model): item = models.ForeignKey(InspectionItem) question = models.CharField(max_length=200) question_pass = models.BooleanField() class InspectionResult(models.Model): question

  • 0
class InspectionQuestion(models.Model):
    item = models.ForeignKey(InspectionItem)
    question = models.CharField(max_length=200)
    question_pass = models.BooleanField()    

class InspectionResult(models.Model):
    question = models.ForeignKey(InspectionQuestion)
    vehicle = models.ForeignKey(Vehicle)
    result = models.BooleanField()

From the above class, I’d like to be able to get a list of questions answered per vehicle, then for each question, show if the result has always been a pass (question_pass == result), fail (result == False), resolved (used to be a fail, but later on was changed to pass).

My main problem I guess is that each vehicle can have the same question answered several times, so I need a way to factor this in the query. I really don’t have an idea on how to get this running, so I’m hoping someone has an idea. Thanks.

  • 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-26T04:09:15+00:00Added an answer on May 26, 2026 at 4:09 am

    It seems some SQL has proved handy…if someone has an idea on how to do this in the Django ORM, I’d be happy to try their idea. Here’s what I have so far:

    I came across this handy link showing a how to run slightly complex SQL from Django. So using that, I used this query to pull up the questions and responses for each:

    question_list = query_to_dict("""
      SELECT question_id, question, item, array_agg(pass_fail) AS results
      FROM "vehicles_inspectionresult"
      INNER JOIN "vehicles_inspectionquestion" ON 
      ("vehicles_inspectionresult"."question_id" = "vehicles_inspectionquestion"."id")
      INNER JOIN "vehicles_inspectionitem" ON 
      ("vehicles_inspectionquestion"."item_id" = "vehicles_inspectionitem"."id")
      WHERE "vehicles_inspectionresult"."vehicle_id" = %s
      GROUP BY item, question_id, question
      ORDER BY item;
    """, vehicle.id)
    

    The pass_fail variable is an addition to the InspectionResult class…it’s for telling if a response is correct or not by comparing the question’s answer with what was posted when saving.

    The rest is mostly template code to group the questions into their specific item groups using Django’s{% regroup %} template tag, but the main logic in my view is the above line. I hope this helps someone in future.

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

Sidebar

Related Questions

class Foo(models.Model): title = models.CharField(max_length=20) slug = models.SlugField() Is there a built-in way to
class Person(models.Model): name = models.CharField(max_length=100) class Entry(models.Model): text = models.CharField(max_length=100) person = models.ManyToManyField(Person, blank=True,
class Book(models.Model): name = models.CharField(max_length=127, blank=False) class Author(models.Model): name = models.CharField(max_length=127, blank=False) books =
class Tag(models.Model): name = models.CharField(maxlength=100) class Blog(models.Model): name = models.CharField(maxlength=100) tags = models.ManyToManyField(Tag) Simple
class Order(models.Model): ... class OrderItem(models.Model) order = models.ForeignKey(Order) product = models.ForeignKey(Product) quantity = models.PositiveIntegerField()
class Foo { public: explicit Foo(double item) : x(item) {} operator double() {return x*2.0;}
class Message(db.Model): user = db.ReferenceProperty(User, required=True, collection_name='Message_set') text = db.TextProperty(required=True) I tried this but
class Foo { static bool Bar(Stream^ stream); }; class FooWrapper { bool Bar(LPCWSTR szUnicodeString)
class A : IFoo { } ... A[] arrayOfA = new A[10]; if(arrayOfA is
class someclass {}; class base { int a; int *pint; someclass objsomeclass; someclass* psomeclass;

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.