Hi Rajesh, Thanks for the reply. Using select_related() isn't working either. I tried that earlier :) I'm not as familiar with running Django form the command line as I am with Rails - I'm not quite sure how to tell Python which settings module to use. Can you please help me out?
TIA, Brandon On Apr 9, 10:33 am, Rajesh Dhawan <[EMAIL PROTECTED]> wrote: > On Apr 9, 11:20 am, Brandon Taylor <[EMAIL PROTECTED]> wrote: > > > > > Hi everyone, > > > I'm trying to build a simple search. > > > Here are the models in question: > > > class WorkCategory(models.Model): > > title = models.CharField(max_length = 30) > > position = models.PositiveSmallIntegerField() > > > def __unicode__(self): > > return self.title > > > class Admin: > > ordering = ('position',) > > search_fields = ('title') > > > class Meta: > > verbose_name_plural = 'Work Categories' > > > class WorkSample(models.Model): > > work_category = models.ForeignKey(WorkCategory) > > work_type = models.ForeignKey(WorkType) > > client = models.ForeignKey(Client) > > title = models.CharField(max_length = 75) > > desc = models.TextField() > > thumbnail = models.ImageField(upload_to = 'images') > > sample_image = models.ImageField(upload_to = 'images') > > sample_alt = models.CharField(max_length = 75) > > > def __unicode__(self): > > return self.title > > > class Admin: > > list_display = ('title','desc','sample_alt','slug') > > list_filter = ('work_category', 'work_type', 'client') > > search_fields = ('client', 'desc') > > js = > > ('/media/tinymce/jscripts/tiny_mce/tiny_mce.js','/media/js/ > > textareas.js',) > > > class Meta: > > verbose_name_plural = 'Work Samples' > > > Here is my views.py: > > > def search(request): > > query = request.GET.get('q','') > > if query: > > qset = ( > > Q(title__icontains=query) | > > Q(work_category__title__icontains=query) # <-- NOT > > WORKING > > ) > > > results = WorkSample.objects.filter(qset).distinct() > > Try: > > results = WorkSample.objects.select_related().filter(qset).distinct() > > If that doesn't work, print out the SQL that Django is generating and > executing so you can see what's causing the > problem:http://www.djangoproject.com/documentation/faq/#how-can-i-see-the-raw... > > -Rajesh D --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---