Skip to content

Commit

Permalink
Don't use nested enum classes in README
Browse files Browse the repository at this point in the history
Refs #57
  • Loading branch information
akx committed Jun 23, 2016
1 parent d16df45 commit 3cef7ad
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ EnumField, EnumIntegerField
from enumfields import EnumField
from enumfields import Enum # Uses Ethan Furman's "enum34" backport
class MyModel(models.Model):
class Color(Enum):
RED = 'r'
GREEN = 'g'
BLUE = 'b'
class Color(Enum):
RED = 'r'
GREEN = 'g'
BLUE = 'b'
class MyModel(models.Model):
color = EnumField(Color, max_length=1)
Elsewhere:

.. code-block:: python
m = MyModel.objects.filter(color=MyModel.Color.RED)
m = MyModel.objects.filter(color=Color.RED)
``EnumIntegerField`` works identically, but the underlying storage mechanism is
an ``IntegerField`` instead of a ``CharField``.
Expand All @@ -54,20 +54,19 @@ names. You can provide custom labels with a nested "Labels" class.
from enumfields import EnumField, Enum # Our own Enum class
class MyModel(models.Model):
class Color(Enum):
RED = 'r'
GREEN = 'g'
BLUE = 'b'
class Color(Enum):
RED = 'r'
GREEN = 'g'
BLUE = 'b'
class Labels:
RED = 'A custom label'
class Labels:
RED = 'A custom label'
class MyModel(models.Model):
color = EnumField(Color, max_length=1)
assert MyModel.Color.GREEN.label == 'Green'
assert MyModel.Color.RED.label == 'A custom label'
assert Color.GREEN.label == 'Green'
assert Color.RED.label == 'A custom label'
.. _PEP435: http://www.python.org/dev/peps/pep-0435/
Expand Down

0 comments on commit 3cef7ad

Please sign in to comment.