toastdriven/django-haystack — Issue #468: Filter does not work with ForeignKeys
Author: ProgVal
Created: 2011-12-26 12:55:43+00:00
State: open

Hi,

I have this as models.py:

```
class Entry(models.Model):
content = models.TextField()
author = models.ForeignKey(People, related_name='author')
updated = models.DateTimeField(auto_now=True)
in_reply_to = models.ForeignKey('self', null=True, blank=True,
related_name='entry_in-reply-to')
```

and this as search_sites.py:

```
import haystack
from haystack import site
from haystack import indexes

from myapp import models

class EntryIndex(indexes.RealTimeSearchIndex):
author = indexes.CharField(model_attr='author')
content = indexes.CharField(document=True, model_attr='content')
updated = indexes.DateTimeField(model_attr='updated')
in_reply_to = indexes.CharField(model_attr='in_reply_to', null=True)

site.register(models.Entry, EntryIndex)
```

And this code raises an AssertionError:

```
query2 = SearchQuerySet().models(Entry).filter(in_reply_to=entries[0])
assert all([x.object.in_reply_to == entries[0] for x in query2 if x.object is not None])
```