{"action":"created","issue":{"url":"https://api.github.com/repos/modlinltd/django-advanced-filters/issues/29","repository_url":"https://api.github.com/repos/modlinltd/django-advanced-filters","labels_url":"https://api.github.com/repos/modlinltd/django-advanced-filters/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/modlinltd/django-advanced-filters/issues/29/comments","events_url":"https://api.github.com/repos/modlinltd/django-advanced-filters/issues/29/events","html_url":"https://github.com/modlinltd/django-advanced-filters/issues/29","id":165214335,"number":29,"title":"Add custom list filter to advanced_filter_fields list","user":{"login":"hermanocabral","id":1000585,"avatar_url":"https://avatars.githubusercontent.com/u/1000585?v=3","gravatar_id":"","url":"https://api.github.com/users/hermanocabral","html_url":"https://github.com/hermanocabral","followers_url":"https://api.github.com/users/hermanocabral/followers","following_url":"https://api.github.com/users/hermanocabral/following{/other_user}","gists_url":"https://api.github.com/users/hermanocabral/gists{/gist_id}","starred_url":"https://api.github.com/users/hermanocabral/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hermanocabral/subscriptions","organizations_url":"https://api.github.com/users/hermanocabral/orgs","repos_url":"https://api.github.com/users/hermanocabral/repos","events_url":"https://api.github.com/users/hermanocabral/events{/privacy}","received_events_url":"https://api.github.com/users/hermanocabral/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-13T00:57:16Z","updated_at":"2016-08-05T11:10:49Z","closed_at":null,"body":"Howdy,\r\n\r\nHow would I go about having a custom filter in the advanced_filter_fields list?\r\n\r\nI have a scenario where I have a Person model with gender defined as a boolean field, but I'd like to give admin users the option to filter by \"Male\"/\"Female\" instead of by True/False.\r\n\r\nI can use something like the GenderListFilter below in the admin page, but how do I go about doing something similar with advanced filters?\r\n\r\nThanks.\r\n\r\n```\r\nclass Person(models.Model):\r\n    is_male = models.BooleanField(verbose_name='Is Male', blank=False, null=False, default=False)\r\n\r\n\r\nclass GenderListFilter(admin.SimpleListFilter):\r\n    title = 'Gender'\r\n    parameter_name = 'gender'\r\n\r\n    def lookups(self, request, model_admin):\r\n        return (\r\n            ('M', 'Male'),\r\n            ('F', 'Female')\r\n        )\r\n\r\n    def queryset(self, request, queryset):\r\n        if not self.value():\r\n            return queryset\r\n\r\n        if self.value().lower() == 'm':\r\n            return queryset.filter(is_male=True)\r\n        else:\r\n            return queryset.filter(is_male=False)\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/modlinltd/django-advanced-filters/issues/comments/237824726","html_url":"https://github.com/modlinltd/django-advanced-filters/issues/29#issuecomment-237824726","issue_url":"https://api.github.com/repos/modlinltd/django-advanced-filters/issues/29","id":237824726,"user":{"login":"asfaltboy","id":321520,"avatar_url":"https://avatars.githubusercontent.com/u/321520?v=3","gravatar_id":"","url":"https://api.github.com/users/asfaltboy","html_url":"https://github.com/asfaltboy","followers_url":"https://api.github.com/users/asfaltboy/followers","following_url":"https://api.github.com/users/asfaltboy/following{/other_user}","gists_url":"https://api.github.com/users/asfaltboy/gists{/gist_id}","starred_url":"https://api.github.com/users/asfaltboy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asfaltboy/subscriptions","organizations_url":"https://api.github.com/users/asfaltboy/orgs","repos_url":"https://api.github.com/users/asfaltboy/repos","events_url":"https://api.github.com/users/asfaltboy/events{/privacy}","received_events_url":"https://api.github.com/users/asfaltboy/received_events","type":"User","site_admin":false},"created_at":"2016-08-05T11:10:49Z","updated_at":"2016-08-05T11:10:49Z","body":"Hi @hermanocabral,\r\n\r\nWe don't support something like operator customization per field right now.\r\n\r\nYou could, if that was the only boolean field you wanted to filter on for this ModelAdmin, subclass the [`AdvancedFilterQueryForm` form][1] and specify your own label:\r\n\r\n```python\r\nclass CustomLabelAdvancedFilterQueryForm(AdvancedFilterQueryForm):\r\n    \"\"\" Build the query from field, operator and value, customizing the boolean values \"\"\"\r\n    OPERATORS = AdvancedFilterQueryForm.OPERATORS + (\r\n        (\"istrue\", _(\"Is Male\")),\r\n        (\"isfalse\", _(\"Is Female\")),\r\n    )\r\n```\r\n\r\nReplacing the above form means you'd also have to construct your own formset, and use it in `AdvancedFilterForm. initialize_form `\r\n\r\nThough to be clear, I would probably make a field such as gender selection, an int/char field with 2 choices, which would be properly rendered by our form.\r\n\r\n[1]: https://github.com/modlinltd/django-advanced-filters/blob/develop/advanced_filters/forms.py#L46"}}
{"actor":{"display_login":"asfaltboy"}}