title: How can I get one object when we select object from dependent dropdown list in django
body: <p>(I am working on dependent dropdown list in Django) I have two dropdown lists first is Company and second is Car. when I select company Name from first dropdown list like Toyota all cars are coming related to Toyota Company, when I select any car from second dropdown (Car Dropdown) then it's showing nothing against Toyota I only need one car which I have selected, How can I do this ?
  Any one can help ?</p>
  <p><a href="https://i.stack.imgur.com/cUPgO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cUPgO.png" alt="enter image description here" /></a></p>
  <p><strong>It is showing empty page like this</strong></p>
  <p><a href="https://i.stack.imgur.com/MYub3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MYub3.png" alt="enter image description here" /></a></p>
  <p><strong>Here is my code</strong></p>
  <p><strong>models.py</strong></p>
  <pre><code>      class Car(models.Model):
           CarID = models.AutoField(primary_key=True)
           CarName = models.CharField(max_length=500, blank=True, null=True, verbose_name=&quot;Car Name&quot;)
           company = models.ForeignKey(Company, verbose_name=&quot;Company Name&quot;, on_delete=models.CASCADE, default=&quot;&quot;)
           type = models.ForeignKey(CarType, verbose_name=&quot;Vehicle Type&quot;, on_delete=models.CASCADE)
           CarImage = models.ImageField(upload_to='productimg', verbose_name=&quot;Vehicle Image&quot;)
           RefNo = models.CharField(max_length=500,verbose_name=&quot;Ref No&quot;, null=True, blank=True)
           ChassisNo = models.CharField(max_length=500,verbose_name=&quot;Chassis No&quot;, null=True, blank=True)
           ModelCode = models.CharField(max_length=500,verbose_name=&quot;Model Code&quot;, null=True, blank=True)
           EngineSize = models.CharField(max_length=500,verbose_name=&quot;Engine Size&quot;, null=True, blank=True)
           Location = models.CharField(max_length=500,verbose_name=&quot;Location&quot;, null=True, blank=True)
           Version = models.CharField(max_length=500,verbose_name=&quot;Version/Class&quot;, null=True, blank=True)
           Drive = models.CharField(max_length=500,verbose_name=&quot;Drive&quot;, null=True, blank=True)
           Transmission = models.CharField(max_length=500,verbose_name=&quot;Transmission&quot;, null=True, blank=True)
           mfdate = models.DateField(auto_now_add=False, blank= True,null=True, verbose_name=&quot;Manufacturing Date&quot;)
           Mileage = models.CharField(max_length=500,verbose_name=&quot;Mileage&quot;, null=True, blank=True)
           EngineCode = models.CharField(max_length=500,verbose_name=&quot;Engine Code&quot;, null=True, blank=True)
           steering = models.ForeignKey(Steering, verbose_name=&quot;Steering&quot;, on_delete=models.CASCADE, default=&quot;&quot;)        
           ExtColor = models.CharField(max_length=500,verbose_name=&quot;Ext Color&quot;, null=True, blank=True)
           Fuel = models.CharField(max_length=500,verbose_name=&quot;Fuel&quot;, null=True, blank=True)
           Seats = models.CharField(max_length=500,verbose_name=&quot;Seats&quot;, null=True, blank=True)
           Door = models.CharField(max_length=500,verbose_name=&quot;Door&quot;, null=True, blank=True)
           M3 = models.CharField(max_length=500,verbose_name=&quot;M3&quot;, null=True, blank=True)
           Dimensions = models.CharField(max_length=500,verbose_name=&quot;Dimensions&quot;, null=True, blank=True)
           Weight = models.CharField(max_length=500,verbose_name=&quot;Vehicle Weight&quot;, blank=True, null=True)
           MaxCap = models.CharField(max_length=500,verbose_name=&quot;Max Capicity&quot;, null=True, blank=True)
           country = models.ForeignKey(Country, verbose_name=&quot;CountryName&quot;, on_delete=models.CASCADE, default=&quot;&quot;)
           pricerange = models.ForeignKey(PriceRange, verbose_name=&quot;Price Range&quot;, on_delete=models.CASCADE, default=&quot;&quot;)
           discount = models.ForeignKey(Discount, verbose_name=&quot;By Discount&quot;, on_delete=models.CASCADE, default=&quot;&quot;)
           othercategorie = models.ForeignKey(OtherCategorie, verbose_name=&quot;Other Categories&quot;, on_delete=models.CASCADE, default=&quot;&quot;)
           Description = models.TextField(verbose_name=&quot;Description&quot;, null=True, blank=True)
           Price = models.CharField(max_length=500,verbose_name=&quot;Vehicle Price&quot;, null=True, blank=True)
           TotalPrice = models.CharField(max_length=500,verbose_name=&quot;Total Price&quot;, null=True, blank=True)
  
           @staticmethod
           def get_all_cars():
               return Car.objects.all()
  
           @staticmethod
           def get_all_cars_by_CompanyId(company_id):
               if company_id:
                   return Car.objects.filter(company=company_id)
               else:
                   return Car.get_all_cars()
  
           def __str__(self):
               return self.CarName
  </code></pre>
  <p><strong>views.py</strong></p>
  <pre><code>  def searchdd(request):
  
      carForm = Car.objects.all()   
      companyname = request.POST.get('company_ddl')
      carname = request.POST.get('car_name')
  
     if request.method == &quot;POST&quot;:
         carForm = Car.objects.filter(company=companyname)
  
         context = {'carForm':carForm} 
         return render(request, 'app/searchdd.html', context)
  
      # **this method for select just one car against company**
     if request.method == &quot;POST&quot;:      
         carForm = Car.objects.filter(CarName=carname)
      
         context = {'carForm':carForm} 
         return render(request, 'app/searchdd.html', context)
  </code></pre>
  <p><strong>home.html</strong></p>
  <pre><code>     &lt;form method=&quot;post&quot; id=&quot;indexForm&quot; action=&quot;/searchdd&quot; data-cars-url=&quot;{% url 'ajax_load_cars' %}&quot;&gt;
      {% csrf_token %}
    &lt;div class=&quot;col-md-12&quot;&gt;
      &lt;div class=&quot;row&quot;&gt;
       
        &lt;div class=&quot; col-md-3&quot;&gt;
          &lt;label for=&quot;&quot; class=&quot;white&quot;&gt;Make&lt;/label&gt;
          &lt;select id=&quot;companyddl&quot; name=&quot;company_ddl&quot; class=&quot;searchengine dp-list&quot;&gt;              
            &lt;option disabled selected=&quot;true&quot; value=&quot;&quot;&gt;--Select Make--&lt;/option&gt;            
            {% for company in companies %}             
            &lt;option value=&quot;{{company.CompanyID}}&quot;&gt;{{company.CompanyName}}&lt;/option&gt;              
            {% endfor %}              
          &lt;/select&gt;
        &lt;/div&gt;
  
        &lt;div class=&quot; col-md-3&quot;&gt;
          &lt;label for=&quot;&quot; class=&quot;white&quot;&gt;Model&lt;/label&gt;
          &lt;select id=&quot;carddl&quot; name=&quot;car_name&quot; class=&quot;searchengine dp-list&quot;&gt;
            &lt;option disabled selected=&quot;true&quot; value=&quot;&quot;&gt;--Select Model--&lt;/option&gt;                           
          &lt;/select&gt;
        &lt;/div&gt;
        &lt;/div&gt;
               &lt;div class=&quot; col-md-3&quot;&gt;
          &lt;label class=&quot;white&quot;&gt;Search &lt;/label&gt;            
          &lt;button class=&quot;btn-dark&quot; type=&quot;submit&quot; value=&quot;search&quot;&gt;&lt;i class=&quot;fa fa-search&quot;&gt;&lt;/i&gt;&amp;nbsp;&amp;nbsp;Search Here&amp;nbsp;&amp;nbsp;&lt;/button&gt;            
        &lt;/div&gt;
        &lt;/div&gt;
  </code></pre>
  <p><strong>urls.py</strong></p>
  <pre><code>  urlpatterns = [
       path('', views.home, name='home'),
       path('search', views.search, name='search'),    
       path('load-cars', views.load_cars, name='ajax_load_cars'),
       path('searchdd', views.searchdd, name='searchdd'),
    ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  </code></pre>