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()
else:
results = []
return render_to_response("search.html", {"results" : results,
"query" : query})
In my case, the WorkCategory table is populated with 3 records: Print,
Web, Illustration
However, when I search for any of those terms, which should be
associated with a WorkSample by the "work_category" foreign key, I get
zero results back.
What am I doing wrong? Help greatly appreciated!
Brandon
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---