carljm/django-model-utils — pull request #69 by kezabelle (2013-08-02 11:34:45+00:00)
Title: Implementing __contains__ in Choices (do-over)

Having been provisionally accepted as a feature by @carljm in #40, this should enable the following functionality on Choices instances:

```
>>> choices = Choices('x', 'y')
>>> 'x' in choices
True
>>> 'z' in choices
False

>>> choices = Choices(('x' 'display x'), ('y', 'display y'))
>>> 'x' in choices
True
>>> 'display x' in choices
False

>>> choices = Choices(('x' 'attrx', 'display x'), ('y', 'attry', 'display y'))
>>> 'x' in choices
True
>>> 'display x' in choices
False
>>> choices.attrx in choices
True
```

Tests pass locally using `python setup.py test` (in lieu of having all the required `tox` configurations).

I have *not* tackled the idea of checking a sequence is in the `Choices` instance (`('thing, 'another thing') in some_choices`) as in the original ticket, there was no real-world use-case for it that could be found, and none has come to light since.