add fields method limiting the models columns fetched from db

This commit is contained in:
collerek
2020-10-05 09:40:41 +02:00
parent 16b8e95975
commit 287b970a09
16 changed files with 209 additions and 38 deletions

View File

@ -29,7 +29,7 @@ class Track(ormar.Model):
album = await Album.objects.create(name="Brooklyn")
await Track.objects.create(album=album, title="The Bird", position=1)
# explicit preload of related Album Model
# explicit preload of columns Album Model
track = await Track.objects.select_related("album").get(title="The Bird")
assert track.album.name == 'Brooklyn'
# Will produce: True

View File

@ -33,7 +33,7 @@ print('name' in course.__dict__)
print(course.name)
# Math <- value returned from underlying pydantic model
print('department' in course.__dict__)
# False <- related model is not stored on Course instance
# False <- columns model is not stored on Course instance
print(course.department)
# Department(id=None, name='Science') <- Department model
# returned from AliasManager