Joseph Wayodi
unread,Dec 10, 2012, 4:34:43 AM12/10/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django-...@googlegroups.com
Hello,
I'm trying to do a SearchQuerySet filter on a MultiValueField that
contains Dates, and it looks like the only field lookup types that
work are "contains" and "exact". I'd like to be able to use "gt",
"gte", "lt", "lte", "in", and "range". Is this supported at all? Or is
it not implemented in the backend (Xapian) that I'm using?
I'm using Haystack (version 2.0.0-beta from GitHub) with the Xapian
backend (xapian-haystack version 2.0.0 from GitHub).
My code is as below:
models.py
---------
class Movie(models.Model):
year = models.PositiveIntegerField(blank=True, null=True,)
director = models.CharField(max_length=128, blank=True, )
writer = models.CharField(max_length=128, blank=True, )
country = models.CharField(max_length=32, blank=True, )
actors = models.TextField( blank=True, )
plot = models.TextField(blank=True, )
runtime = models.CharField(max_length=128, blank=True, )
class Show(models.Model):
movie = models.ForeignKey('Movie', related_name='shows')
starts = models.DateField(db_index=True,)
search_indexes.py
-----------------
class MovieIndex(indexes.Indexable):
starts = indexes.MultiValueField(null=True,)
def prepare_starts(self, obj):
start_dates = [show.starts for show in obj.shows.all()]
return start_dates
views.py
--------
sqs = SearchQuerySet().filter(django_ct='movies.movie',
starts=datetime.date(2012, 12, 15)) # works
sqs = SearchQuerySet().filter(django_ct='movies.movie',
starts__gt=datetime.date(2012, 12, 15)) # doesn't work
sqs = SearchQuerySet().filter(django_ct='movies.movie',
starts__gte=datetime.date(2012, 12, 15)) # doesn't work
sqs = SearchQuerySet().filter(django_ct='movies.movie',
starts__lt=datetime.date(2012, 12, 15)) # doesn't work
sqs = SearchQuerySet().filter(django_ct='movies.movie',
starts__lte=datetime.date(2012, 12, 15)) # doesn't work
sqs = SearchQuerySet().filter(django_ct='movies.movie',
starts__in=[datetime.date(2012, 12, 15), datetime.date(2012, 12, 17),
datetime.date(2012, 12, 19)]) # doesn't work
sqs = SearchQuerySet().filter(django_ct='movies.movie',
starts__range=[datetime.date(2012, 12, 15), datetime.date(2012, 12,
17)]) # doesn't work
Regards,
Joseph.