Skip to content

Commit de10049

Browse files
committed
more documentation work
1 parent 3df693f commit de10049

File tree

6 files changed

+180
-100
lines changed

6 files changed

+180
-100
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,5 @@ tests/edit_tests/migrations/00*.py
135135
benchmark.db
136136
type_check.py
137137
tests/**/migrations/**py
138+
139+
.DS_Store

doc/source/eccentric_enums.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.. include:: refs.rst
22

3-
.. _eccentric_enums:
3+
.. _eccentric:
44

55
======================
66
Eccentric Enumerations
@@ -52,8 +52,8 @@ Mixed value enumerations are supported. For example:
5252
VAL4 = Decimal('4.5')
5353
5454
55-
``EnumField`` will determine the most appropriate database column type to store
56-
the enumeration by trying each of the supported primitive types in order and
55+
:class:`~django_enum.fields.EnumField` will determine the most appropriate database column type
56+
to store the enumeration by trying each of the supported primitive types in order and
5757
selecting the first one that is symmetrically coercible to and from each
5858
enumeration value. ``None`` values are allowed and do not take part in the
5959
primitive type selection. In the above example, the database column type would
@@ -62,12 +62,12 @@ be a string.
6262
.. note::
6363

6464
If none of the supported primitive types are symmetrically coercible
65-
``EnumField`` will not be able to determine an appropriate column type and
66-
a ``ValueError`` will be raised.
65+
:class:`~django_enum.fields.EnumField` will not be able to determine an appropriate column
66+
type and a ``ValueError`` will be raised.
6767

6868
In these cases, or to override the primitive type selection made by
69-
``EnumField``, pass the ``primitive`` parameter. It may be necessary to extend
70-
one of the supported primitives to make it coercible. It may also be necessary
69+
:class:`~django_enum.fields.EnumField`, pass the ``primitive`` parameter. It may be necessary to
70+
extend one of the supported primitives to make it coercible. It may also be necessary
7171
to override the Enum_'s ``_missing_`` method:
7272

7373
.. code-block:: python
@@ -78,8 +78,8 @@ to override the Enum_'s ``_missing_`` method:
7878
# primitive will be a float
7979
eccentric_float = EnumField(EccentricEnum, primitive=float)
8080
81-
In the above case since ``None`` is an enumeration value, ``EnumField`` will
82-
automatically set null=True on the model field.
81+
In the above case since ``None`` is an enumeration value, :class:`~django_enum.fields.EnumField`
82+
will automatically set null=True on the model field.
8383

8484
Custom Enumeration Values
8585
=========================

doc/source/flag_enums.rst

Lines changed: 0 additions & 11 deletions
This file was deleted.

doc/source/index.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ to:
7777
* Enforce enumeration value consistency at the database level using check constraints by default.
7878
* (TODO) Support native database enumeration column types when available.
7979

80-
django-enum_ provides a new model field type, ``EnumField``, that allows you to treat almost any
81-
PEP 435 enumeration as a database column. ``EnumField`` resolves the correct native Django_ field
82-
type for the given enumeration based on its value type and range. For example, ``IntegerChoices``
83-
that contain values between 0 and 32767 become
84-
`PositiveSmallIntegerField <https://docs.djangoproject.com/en/stable/ref/models/fields/#positivesmallintegerfield>`_.
80+
django-enum_ provides a new model field type, :class:`~django_enum.fields.EnumField`, that allows
81+
you to treat almost any PEP 435 enumeration as a database column.
82+
:class:`~django_enum.fields.EnumField` resolves the correct native Django_ field type for the given
83+
enumeration based on its value type and range. For example, ``IntegerChoices`` that contain values
84+
between 0 and 32767 become `PositiveSmallIntegerField <https://docs.djangoproject.com/en/stable/ref/models/fields/#positivesmallintegerfield>`_.
8585

8686
.. code-block:: python
8787
@@ -111,8 +111,8 @@ that contain values between 0 and 32767 become
111111
int_enum = EnumField(IntEnum, default=IntEnum.ONE)
112112
113113
114-
``EnumField`` **is more than just an alias. The fields are now assignable and accessible as their
115-
enumeration type rather than by-value:**
114+
:class:`~django_enum.fields.EnumField` **is more than just an alias. The fields are now assignable
115+
and accessible as their enumeration type rather than by-value:**
116116

117117
.. code-block:: python
118118
@@ -157,6 +157,9 @@ reduction both speeds up queries and reduces the required storage space. See the
157157
# get all models with RW:
158158
FlagExample.objects.filter(permissions__has_all=Permissions.READ | Permissions.WRITE)
159159
160+
.. note::
161+
162+
The :ref:`has_all` and :ref:`has_any` field lookups are only available for Flag enumerations.
160163

161164
Complex Enumerations
162165
====================
@@ -307,7 +310,6 @@ Please report bugs and discuss features on the
307310
:caption: Contents:
308311

309312
usage
310-
flag_enums
311313
examples
312314
performance
313315
eccentric_enums

doc/source/performance.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ or eccentric enumeration cases.
2424

2525
The marshalling penalty can be eliminated by setting ``coerce`` to
2626
``False``. This will require the developer to manually coerce the
27-
``EnumField`` value to an Enum_ type object and is therefore usually
27+
:class:`~django_enum.fields.EnumField` value to an Enum_ type object and is therefore usually
2828
not recommended - but may be appropriate if the dominate use case involves
2929
high volume serialization to a raw value instead.
3030

@@ -40,7 +40,7 @@ There is an obvious storage improvement when using a single column bit mask inst
4040
we achieve better query performance as well? The following benchmarks compare storage and query
4141
performance between boolean columns and bit masks.
4242

43-
**Using a flag** ``EnumField`` **out performs boolean columns in both
43+
**Using a flag** :class:`~django_enum.fields.EnumField` **out performs boolean columns in both
4444
storage and query performance in most scenarios.**
4545

4646
.. note::
@@ -57,7 +57,7 @@ storage and query performance in most scenarios.**
5757
No Indexing
5858
-----------
5959

60-
When no indexes are used, the flag ``EnumField`` saves a significant amount
60+
When no indexes are used, the flag :class:`~django_enum.fields.EnumField` saves a significant amount
6161
of space over the boolean column model. The following plot shows the storage
6262
efficiency improvement over boolean columns as the number of flags increases
6363
for each supported RDBMS. The oracle line shows extents which are allocated in
@@ -94,13 +94,14 @@ does a full table scan:
9494
Indexed Exact Queries
9595
---------------------
9696

97-
When an index is used, the flag ``EnumField`` marginally outperforms the
97+
When an index is used, the flag :class:`~django_enum.fields.EnumField` marginally outperforms the
9898
boolean column equivalent in both storage and query performance for exact match
9999
queries. It is also much simpler to define. When using the boolean column
100100
approach a multi-column index must be used. By default PostgreSQL is compiled
101101
with a maximum multi-column index size of 32 columns. This means that masks
102102
with more than 32 flags must be split into multiple multi-column indexes which
103-
will further degrade performance compared to the equivalent flag ``EnumField``.
103+
will further degrade performance compared to the equivalent flag
104+
:class:`~django_enum.fields.EnumField`.
104105

105106
The multi-column limit on MySQL is only 16 columns.
106107

0 commit comments

Comments
 (0)