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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:06:56+00:00 2026-05-25T23:06:56+00:00

I have a model class defined as below: class Vehicle(models.Model): stock_number = models.CharField(max_length=6) vin

  • 0

I have a model class defined as below:

class Vehicle(models.Model):
    stock_number = models.CharField(max_length=6)
    vin = models.CharField(max_length=17)
    year = models.PositiveSmallIntegerField()
    manufacturer = models.CharField(max_length=15)
    manufacturer_popularity = models.CharField(max_length=1, blank=True, null=True)
    model = models.CharField(max_length=20)
    series = models.CharField(max_length=35, blank=True, null=True)
    exterior_colour = models.CharField(max_length=25)
    interior_colour = models.CharField(max_length=25)
    interior_type = models.CharField(max_length=25)
    doors = models.PositiveSmallIntegerField()
    passengers = models.PositiveSmallIntegerField()
    body_style = models.CharField(max_length=30)
    transmission = models.CharField(max_length=50)
    fuel_type = models.CharField(max_length=50)
    engine_capacity = models.DecimalField(max_digits=2, decimal_places=1)
    cylinders = models.PositiveSmallIntegerField()
    drive_train = models.CharField(max_length=50)

What I want to do is to query two databases based on the above class then display the data in a template while showing the differences between each paired Vehicle entry in red. The querying bit isn’t the main issue I guess since I’ll need something like:

set1 = Vehicle.objects.all()
set2 = Vehicle.objects.using('other_db').all()

But how can I have the pairing and display being handled? I hope someone can show me the light here.

UPDATE 1

vehicles = []
for v1 in set1:
    for v2 in set2:
        if v1['stock_number'] == v2['stock_number']:
            vehicle1 = vehicle2 = {}
            vehicle1['vehicle_1'] = v1
            vehicle2['vehicle_2'] = v2
            vehicles.append(vehicle1)
            vehicles.append(vehicle2)
        else:
            vehicle1 = vehicle2 = {}
            vehicle1['vehicle_1'] = v1
            vehicle2['vehicle_2'] = {}
            vehicles.append(vehicle1)
            vehicles.append(vehicle2)
  • 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-25T23:06:57+00:00Added an answer on May 25, 2026 at 11:06 pm

    The idea

    from itertools import izip
    
    for obj1, obj2 in izip(set1, set2):
        for field in obj1._meta.fields:
            if field.value_from_object(obj1) == field.value_from_object(obj2):
                print 'Same value', field.value_from_object(obj1)
            else:
                print 'Obj1 has', field.value_from_object(obj1)
                print 'Obj2 has', field.value_from_object(obj2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, i have the following model defined, class header(models.Model): title = models.CharField(max_length = 255)
I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other
I have a model: class Example(models.Model): unique_hash = models.CharField(max_length=32,unique=True) content = models.FileField(upload_to='source',blank=True,verbose_name=HTML Content File)
Let's say I have a class structure that is defined below: Class Item(models.Model): ...
Lets say I have model inheritance set up in the way defined below. class
I have a model defined this way class Lga < ActiveRecord::Base validates_uniqueness_of :code validates_presence_of
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
I have a Review Model like the one defined below (I removed a bunch
I have a few tables that I've defined like the below examples: class TableA
first time using Asp.Net MVC here. I have a model class defined with 3

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.