title: django queryset - need advice on queryset in view - filters and setting relationships
body: <p>I am trying to generate a template/report that lists all of the listings (ads) for a customer.  Most everything relates to the ID of the Listings table.  A customer can have many listings, a listing will only have one listing type, and a listing can have many images.  I know my <code>view.py</code> is messed up -- ideally I'd like to send a minimal amount of data to the template.  So I would like to only send listings, images and listingtype (1, 2, or 3) data that relates to listings for a specific customer.  I'm struggling with the queryset, and building the context.  I'm sure I have to add more objects to the context than are currently listed.</p>
  
  <p>I'm am presuming once I get the data to the template I will have to build a table row by row, and do some if/then stuff in the template to deal with the different listingtypes.  Let me know if you know of an easier way.</p>
  
  <p>Models.py</p>
  
  <pre><code>class Customer(models.Model):
      name = models.CharField(max_length=20, blank=True)
      email = models.CharField(max_length=50, blank=True)
      user = models.ForeignKey(User, unique=True)
      def __unicode__(self):
          return unicode(self.user)
  
  class ListingType(models.Model):
      desc = models.CharField(max_length=35, blank=True)
      def __unicode__(self):
          return self.desc
  
  class Listings(models.Model):
      createdate = models.DateTimeField(auto_now_add=True)
      price = models.IntegerField(null=True, blank=True)
      listing_type = models.ForeignKey(ListingType)
      customer = models.ForeignKey(Customer)
  
  class Listingtype1(models.Model):
      manufacturer = models.CharField(max_length=35, blank=True)
      mfg_no = models.CharField(max_length=35, blank=True)
      typespecific1 = models.CharField(max_length=35, blank=True)
      typespecific2 = models.CharField(max_length=35, blank=True)
      listings = models.ForeignKey(Listings)
  
  class Listingtype2(models.Model):
      manufacturer = models.CharField(max_length=35, blank=True)
      mfg_no = models.CharField(max_length=35, blank=True)
      typespecific1 = models.CharField(max_length=35, blank=True)
      typespecific2 = models.CharField(max_length=35, blank=True)
      listings = models.ForeignKey(Listings)
  
  class Listingtype3(models.Model):
      manufacturer = models.CharField(max_length=35, blank=True)
      mfg_no = models.CharField(max_length=35, blank=True)
      typespecific1 = models.CharField(max_length=35, blank=True)
      typespecific2 = models.CharField(max_length=35, blank=True)
      listings = models.ForeignKey(Listings)
  
  class Image(models.Model):
      title = models.CharField(max_length=60, blank=True, null=True)
      image = models.ImageField(upload_to="images/", blank=True, null=True)
      thumbnail = models.ImageField(upload_to="images/", blank=True, null=True)
      listings = models.ForeignKey(Listings)
  </code></pre>
  
  <p>Views.py (work in progress)</p>
  
  <pre><code>def listings_customer(request, user_id):
      customer = get_object_or_404(Customer, user=user_id)
      cusnum=customer.id
      listings = Listings.objects.filter(customer=cusnum)
      image = Image.objects.all()
      context=Context({
          'title': 'Listings',
          'customer': customer,
          'listings' : listings,        
          'image' : image,        
          })
      return render_to_response('bsmain/listings.html', context)    
  </code></pre>