{"issue":{"state":"open","pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"user":{"avatar_url":"https://secure.gravatar.com/avatar/a9104150b5c7a69b624af8da7f5af220?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"a9104150b5c7a69b624af8da7f5af220","url":"https://api.github.com/users/gatesy","login":"gatesy","id":355273},"milestone":null,"labels":[],"assignee":null,"updated_at":"2011-11-12T15:37:04Z","comments":1,"closed_at":null,"url":"https://api.github.com/repos/toastdriven/django-haystack/issues/382","body":"Hi,\r\n\r\nI have recently upgraded the Whoosh and Haystack versions on a system that was running 0.38 and 1.0.1-final to 1.8.4 and 1.2.4 respectively (it is running Python 2.6.5 too). I stopped getting the correct search results due to a boolean field in the search index that was being used for filtering having a different behaviour:\r\n\r\n```python\r\nclass ProductIndex(SearchIndex):\r\n    text = CharField(document=True, use_template=True)\r\n    retail_price = FloatField()\r\n    trade_price = FloatField()\r\n    trade_only = BooleanField(default=False)\r\n    date_added = DateTimeField(model_attr='added')\r\n    \r\n    def prepare_trade_only(self, obj):\r\n        \r\n        # The logic here is lifted from 'products.view'; if one category is \"retail\" or\r\n        # not \"trade\", then the product is *not* trade only.\r\n        for category in obj.category.all():\r\n            if not category.trade_type or category.retail_type:\r\n                return False\r\n        return True\r\n    \r\n    def prepare_retail_price(self, obj):\r\n        if obj.retail_sale_price is not None:\r\n            return zfill(str(obj.retail_sale_price), pad_width)\r\n        else:\r\n            return zfill(str(obj.retail_price), pad_width)\r\n        \r\n    def prepare_trade_price(self, obj):\r\n        if obj.trade_sale_price is not None:\r\n            return zfill(str(obj.trade_sale_price), pad_width)\r\n        else:\r\n            return zfill(str(obj.trade_price), pad_width)\r\n\r\n    def update_object(self, instance, **kwargs):\r\n        if instance.visible is True:\r\n            super(ProductIndex, self).update_object(instance, **kwargs)\r\n        else:\r\n            super(ProductIndex, self).remove_object(instance, **kwargs)\r\n    \r\n    def index_queryset(self):\r\n        \"\"\"Used when the entire index for model is updated.\"\"\"\r\n        return Product.objects.filter(visible=True)\r\n\r\nsite.register(Product, ProductIndex)\r\n```\r\n\r\nThe problem was the `trade_only` field was `True` for every object in the index. This was fixed by changing the `prepare_trade_only` method to:\r\n\r\n```python\r\ndef prepare_trade_only(self, obj):\r\n        \r\n        for category in obj.category.all():\r\n            if not category.trade_type or category.retail_type:\r\n                return ''\r\n        return 'True'\r\n```\r\n\r\nI'm not exactly sure why this is happening, but I suspect that my `False` literal is being converted to a string and then that string is then being converted back to a boolean; note that `bool('False') == True` and that `bool('') == False`.\r\n\r\nI think that my original version is the correct implementation as I should be returning a boolean to fill a boolean field, although I am returning a string in the other two prepare methods to fill a float field!\r\n\r\nI guess what I'm saying is that either the fields should be populated correctly from types that are appropriate to them or the documentation should say that everything is converted to a string (and then back again)?\r\n\r\nCheers,\r\nJames.\r\n","html_url":"https://github.com/toastdriven/django-haystack/issues/382","title":"BooleanField and prepare_FOO","number":382,"id":1131701,"created_at":"2011-06-28T17:22:39Z"},"action":"created","comment":{"user":{"avatar_url":"https://secure.gravatar.com/avatar/5c7a2c2b0b31ec819b0b0315d2236e2a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"5c7a2c2b0b31ec819b0b0315d2236e2a","url":"https://api.github.com/users/waylybaye","login":"waylybaye","id":596620},"updated_at":"2011-11-12T15:37:04Z","url":"https://api.github.com/repos/toastdriven/django-haystack/issues/comments/2717908","body":"+1 for me","id":2717908,"created_at":"2011-11-12T15:37:04Z"}}