Skip to content

Commit

Permalink
Document condition chaining (#975)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikonst committed Sep 3, 2021
1 parent 58ff97f commit be7bf37
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/conditional.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ Conditions expressions using nested list and map attributes can be created with
print(Container.my_map['foo'].exists() | Container.my_list[0].contains('bar'))
Conditions can be composited using & (AND) and | (OR) operators. For the & (AND) operator, the left-hand side
operand can be ``None`` to allow easier chaining of filter conditions:

.. code-block:: python
condition = None
if query.name:
condition &= Person.name == query.name
if query.age:
condition &= Person.age == query.age
results = Person.query(..., filter_condition=condition)
Conditional Model.save
^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -111,6 +128,7 @@ This example will delete the item, only if its `views` attribute is equal to 0.
print(thread_item.delete(Thread.views == 0))
Conditional Operation Failures
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down

0 comments on commit be7bf37

Please sign in to comment.