Here are my models
and the manager
class. I think the problem is in the PostingFilterManager
below. They way I search of the keywords in title
and body_text
is wrong.
I want to query for a list of keywords
in title
and body_text
of Postings
model below. I am not getting any error but at the same time nothing is displayed on browser. I am sure that the filter should return a posting.
class PostingFilterManager(models.Manager):
def get_by_keywords(self,wordlist):
print "called"
posts=super(PostingFilterManager,self).get_query_set().filter
(Q(body_text__in=wordlist) | Q(title__in=wordlist))
print posts
return posts
class Postings(models.Model):
carinfo=models.ForeignKey('CarInfo')
title = models.CharField(max_length=100, blank=True)
body_text = models.TextField(blank=True)
objects=models.Manager()
filters=PostingFilterManager()
def __unicode__(self):
return unicode(self.website)
my view:
def detail(request,year):
result=Postings.filters.get_by_keywords(['hello'.'world','clean'])
return HttpResponse(result)