If anyone could have a look it would be much appreciated. -Tom
On Sat, Sep 27, 2008 at 6:40 PM, Tom MacKenzie <[EMAIL PROTECTED]>wrote: > http://django.pastebin.com/d1c579dbf > > Thanks! > > > On Sat, Sep 27, 2008 at 5:48 PM, Ovnicraft <[EMAIL PROTECTED]> wrote: > >> is posible use pastebin? http://django.pastebin.com/ >> >> 2008/9/27 [EMAIL PROTECTED] <[EMAIL PROTECTED]> >> >>> >>> my view is below. >>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> >>> <html lang="en"> >>> <head> >>> <title>Search{% if query %} Results{% endif %}</title> >>> </head> >>> <body> >>> <h1>Search</h1> >>> <form action="." method="GET"> >>> <label for="q">Search: </label> >>> <input type="text" name="q" value="{{ query|escape }}"> >>> <input type="submit" value="Search"> >>> </form> >>> >>> {% if query %} >>> <h2>Results for "{{ query|escape }}":</h2> >>> >>> {% if results %} >>> <ul> >>> {% for company in results %} >>> <li>{{ company|escape }}</l1> >>> {% endfor %} >>> </ul> >>> {% else %} >>> <p>No companys found</p> >>> {% endif %} >>> {% endif %} >>> </body> >>> </html> >>> >>> >>> >>> On Sep 27, 4:45 pm, "[EMAIL PROTECTED]" >>> >>> <[EMAIL PROTECTED]> wrote: >>> > 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 >>> > }) >>> >>> >> >> >> -- >> [b]question = (to) ? be : !be; .[/b] >> >> >> >> > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---