Skip to content

Commit

Permalink
Added simple docs to examples, all added examples used tested
Browse files Browse the repository at this point in the history
  • Loading branch information
grigi committed Oct 10, 2019
1 parent 6675b54 commit f428a68
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=C0330,C0412,W0212,W0613,R0902,R0903,
disable=C0330,C0412,W0212,W0613,R0902,R0903,R0904,
# tune down below here
C0103,C0111,R1702,R0912,R0913,R0914,R0915

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog
=========
0.14.0
------
.. warning::
.. caution::
**This release drops support of Python 3.5:**

Tortoise ORM now requires a minimum of CPython 3.6 or PyPy3.6-7.1
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def __getattr__(cls, name):
# -- Project information -----------------------------------------------------


project = 'Tortoise'
copyright = '2018, Andrey Bondar' # pylint: disable=W0622
author = 'Andrey Bondar'
project = 'Tortoise ORM'
copyright = '2018-2019, Andrey Bondar & Nickolas Grigoriadis' # pylint: disable=W0622
author = 'Andrey Bondar & Nickolas Grigoriadis'


def get_version():
Expand Down
95 changes: 95 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
.. _examples:

========
Examples
========


.. rst-class:: html-toggle

.. _example_basic:

Basic
=====
.. literalinclude:: ../examples/basic.py


.. rst-class:: html-toggle

.. _example_basic_comments:

Basic with comments
===================
.. literalinclude:: ../examples/basic_comments.py


.. rst-class:: html-toggle

.. _example_prefetching:

Prefetching
===========
.. literalinclude:: ../examples/complex_prefetching.py


.. rst-class:: html-toggle

.. _example_transactions:

Transactions
============
.. literalinclude:: ../examples/transactions.py


.. rst-class:: html-toggle

.. _example_aggregation:

Aggregation
===========
.. literalinclude:: ../examples/aggregation.py


.. rst-class:: html-toggle

.. _example_schema_create:

Schema creation
===============
.. literalinclude:: ../examples/schema_create.py


.. rst-class:: html-toggle

.. _example_two_databases:

Two Databases
=============
.. literalinclude:: ../examples/two_databases.py


.. rst-class:: html-toggle

.. _example_filtering:

Filtering
=========
.. literalinclude:: ../examples/complex_filtering.py


.. rst-class:: html-toggle

.. _example_relations:

Relations
=========
.. literalinclude:: ../examples/relations.py


.. rst-class:: html-toggle

.. _example_relations_recursive:

Schema creation
===============
.. literalinclude:: ../examples/relations_recursive.py
2 changes: 1 addition & 1 deletion docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@ After that you can start using your models:
.. note::
You can read more examples (including transactions, several databases and a little more complex querying) in
`examples <https://github.com/tortoise/tortoise-orm/tree/master/examples>`_ directory of project
:ref:`examples`
4 changes: 1 addition & 3 deletions docs/query.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,4 @@ Sometimes it is required to fetch only certain related records. You can achieve
Prefetch('events', queryset=Event.filter(name='First'))
).first()
You can view full example here: ``examples/complex_prefetching.py``

.. literalinclude:: ../examples/complex_prefetching.py
You can view full example here: :ref:`example_prefetching`
1 change: 1 addition & 0 deletions docs/toc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Table Of Contents
index
getting_started
reference
examples
contrib
CHANGELOG
roadmap
Expand Down
3 changes: 3 additions & 0 deletions examples/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ async def run():
await Event.filter(id=event.id).update(name="Updated name")

print(await Event.filter(name="Updated name").first())
# >>> Updated name

await Event(name="Test 2").save()
print(await Event.all().values_list("id", flat=True))
# >>> [1, 2]
print(await Event.all().values("id", "name"))
# >>> [{'id': 1, 'name': 'Updated name'}, {'id': 2, 'name': 'Test 2'}]


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/schema_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Tournament(Model):
id = fields.IntField(pk=True)
name = fields.TextField(description="Tournament name", index=True)
name = fields.CharField(max_length=255, description="Tournament name", index=True)
created = fields.DatetimeField(auto_now_add=True, description="Created datetime")

class Meta:
Expand All @@ -17,7 +17,7 @@ class Meta:

class Event(Model):
id = fields.IntField(pk=True, description="Event ID")
name = fields.TextField(unique=True)
name = fields.CharField(max_length=255, unique=True)
tournament = fields.ForeignKeyField(
"models.Tournament", related_name="events", description="FK to tournament"
)
Expand Down
2 changes: 1 addition & 1 deletion tortoise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,4 +655,4 @@ async def do_stuff():
loop.run_until_complete(Tortoise.close_connections())


__version__ = "0.14.0dev"
__version__ = "0.14.dev0"
4 changes: 2 additions & 2 deletions tortoise/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@


class QuerySetIterable(Protocol[T_co]):
...
... # pylint: disable=W0104


class QuerySetSingle(Protocol[T_co]):
def __await__(self) -> Generator[Any, None, T_co]:
...
... # pylint: disable=W0104


class AwaitableQuery(QuerySetIterable[MODEL]):
Expand Down

0 comments on commit f428a68

Please sign in to comment.