Skip to content

Commit

Permalink
Fix broken Pepy link in README.md (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
lqmanh authored May 15, 2021
1 parent 6edc376 commit 5aaf9df
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Tortoise ORM
.. image:: https://readthedocs.org/projects/tortoise-orm/badge/?version=latest
:target: http://tortoise-orm.readthedocs.io/en/latest/
.. image:: https://pepy.tech/badge/tortoise-orm/month
:target: https://pepy.tech/project/tortoise-orm/month
:target: https://pepy.tech/project/tortoise-orm
.. image:: https://github.com/tortoise/tortoise-orm/workflows/ci/badge.svg
:target: https://github.com/tortoise/tortoise-orm/actions?query=workflow:ci
.. image:: https://coveralls.io/repos/github/tortoise/tortoise-orm/badge.svg
Expand Down Expand Up @@ -101,11 +101,11 @@ You can start writing models like this:
from tortoise.models import Model
from tortoise import fields
class Tournament(Model):
id = fields.IntField(pk=True)
name = fields.TextField()
def __str__(self):
return self.name
Expand All @@ -115,15 +115,15 @@ You can start writing models like this:
name = fields.TextField()
tournament = fields.ForeignKeyField('models.Tournament', related_name='events')
participants = fields.ManyToManyField('models.Team', related_name='events', through='event_team')
def __str__(self):
return self.name
class Team(Model):
id = fields.IntField(pk=True)
name = fields.TextField()
def __str__(self):
return self.name
Expand Down Expand Up @@ -167,23 +167,23 @@ After that you can start using your models:
# Create instance by save
tournament = Tournament(name='New Tournament')
await tournament.save()
# Or by .create()
await Event.create(name='Without participants', tournament=tournament)
event = await Event.create(name='Test', tournament=tournament)
participants = []
for i in range(2):
team = await Team.create(name='Team {}'.format(i + 1))
participants.append(team)
# M2M Relationship management is quite straightforward
# (also look for methods .remove(...) and .clear())
await event.participants.add(*participants)
# You can query a related entity with async for
async for team in event.participants:
pass
# After making a related query you can iterate with regular for,
# which can be extremely convenient when using it with other packages,
# for example some kind of serializers with nested support
Expand All @@ -195,11 +195,11 @@ After that you can start using your models:
selected_events = await Event.filter(
participants=participants[0].id
).prefetch_related('participants', 'tournament')
# Tortoise supports variable depth of prefetching related entities
# This will fetch all events for Team and in those events tournaments will be prefetched
await Team.all().prefetch_related('events__tournament')
# You can filter and order by related models too
await Tournament.filter(
events__name__in=['Test', 'Prod']
Expand Down

0 comments on commit 5aaf9df

Please sign in to comment.