Skip to content

Commit c62f7be

Browse files
document ClassVar usage
1 parent ee66938 commit c62f7be

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

docs/persistence.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,18 @@ field needs to be referenced, such as when specifying sort options in a
271271
When specifying sorting order, the ``+`` and ``-`` unary operators can be used
272272
on the class field attributes to indicate ascending and descending order.
273273

274+
Finally, the ``ClassVar`` annotation can be used to define a regular class
275+
attribute that should not be mapped to the Elasticsearch index::
276+
277+
.. code:: python
278+
279+
from typing import ClassVar
280+
281+
class MyDoc(Document):
282+
title: M[str]
283+
created_at: M[datetime] = mapped_field(default_factory=datetime.now)
284+
my_var: ClassVar[str] # regular class variable, ignored by Elasticsearch
285+
274286
Note on dates
275287
~~~~~~~~~~~~~
276288

0 commit comments

Comments
 (0)