I have a company model which relates to a product model 1-> M. My goal is to search both models and return a result set set that will show the company name and product name that are results of the query. The implementation below only shows the company name.
1. Can I send back the product as well? 2. Should I call a function from the template to retrieve the product? any help appreciated! my models are: class Product(models.Model): co = models.ForeignKey(Company) key = models.ForeignKey(Keyword) name = models.CharField(max_length=100) pub_date = models.DateTimeField(default=datetime.datetime.now()) def __unicode__(self): return self.name class Product(models.Model): co = models.ForeignKey(Company) key = models.ForeignKey(Keyword) name = models.CharField(max_length=100) pub_date = models.DateTimeField(default=datetime.datetime.now()) def __unicode__(self): return self.name My view is... from django.db.models import Q from django.shortcuts import render_to_response from models import Company def search(request): query = request.GET.get('q', '') if query: qset = ( Q(name__icontains=query) | Q(url__icontains=query) | Q(product__name__icontains=query) | Q(product__key__name__icontains=query) ) results = Company.objects.filter(qset).distinct() else: results = [] return render_to_response("foods/search.html", { "results": results, "query": query }) My template is... from django.db.models import Q from django.shortcuts import render_to_response from models import Company def search(request): query = request.GET.get('q', '') if query: qset = ( Q(name__icontains=query) | Q(url__icontains=query) | Q(product__name__icontains=query) | Q(product__key__name__icontains=query) ) results = Company.objects.filter(qset).distinct() else: results = [] return render_to_response("foods/search.html", { "results": results, "query": query }) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---