Permalink
Browse files

added better docs to choices

  • Loading branch information...
1 parent d526f0e commit 848abc4f401b0eb5706b9464c28ce254dbaf913f @WoLpH committed Aug 28, 2013
Showing with 40 additions and 1 deletion.
  1. +40 −1 django_utils/choices.py
View
@@ -5,7 +5,8 @@
Create a :py:class:`Choices` class and add :py:class:`Choice` objects to the
class to define your choices.
-Example:
+Example with explicit values:
+==============================================================================
The normal Django version:
@@ -39,6 +40,44 @@ class Gender(choices.Choices):
Human.create(gender=Human.Gender.Male)
+Example with implicit values:
+==============================================================================
+
+The normal Django version:
+
+.. code-block:: python
+
+ class SomeModel(models.Model):
+ SOME_ENUM = (
+ (1, 'foo'),
+ (2, 'bar'),
+ (3, 'spam'),
+ (4, 'eggs'),
+ )
+ enum = models.IntegerField(choices=SOME_ENUM, default=1)
+
+The Django Utils Choices version:
+
+.. code-block:: python
+
+ from django_utils import choices
+
+ class SomeModel(models.Model):
+ class Enum(choices.Choices):
+ Foo = choices.Choice()
+ Bar = choices.Choice()
+ Spam = choices.Choice()
+ Eggs = choices.Choice()
+
+ enum = models.IntegerField(
+ choices=Enum.choices, default=SomeModel.Foo)
+
+To reference these properties:
+
+.. code-block:: python
+
+ SomeModel.create(enum=SomeModel.Enum.Spam)
+
'''
import collections

0 comments on commit 848abc4

Please sign in to comment.