Skip to content

Commit

Permalink
Add indexes to Model.describe
Browse files Browse the repository at this point in the history
  • Loading branch information
long2ice committed Aug 31, 2021
1 parent 00d17d2 commit af5d87e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Changelog
- Make use/force index available in select type Query. (#893)
- Fix all logging to use Tortoise's logger instead of root logger. (#879)
- Rename `db_client` logger to `tortoise.db_client`.
- Add `indexes` to `Model.describe`.

0.17.6
------
Expand Down
2 changes: 2 additions & 0 deletions tests/test_early_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def test_early_init(self):
"description": "The Event model docstring.",
"docstring": "The Event model docstring.\n\nThis is multiline docs.",
"unique_together": [],
"indexes": [],
"pk_field": {
"name": "id",
"field_type": "IntField",
Expand Down Expand Up @@ -218,6 +219,7 @@ def test_early_init(self):
"description": "The Event model docstring.",
"docstring": "The Event model docstring.\n\nThis is multiline docs.",
"unique_together": [],
"indexes": [],
"pk_field": {
"name": "id",
"field_type": "IntField",
Expand Down
9 changes: 9 additions & 0 deletions tests/utils/test_describe_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def test_describe_model_straight(self):
"description": "Straight auto-mapped fields",
"docstring": None,
"unique_together": [["chars", "blip"]],
"indexes": [],
"pk_field": {
"name": "eyedee",
"field_type": "IntField",
Expand Down Expand Up @@ -366,6 +367,7 @@ def test_describe_model_straight_native(self):
"description": "Straight auto-mapped fields",
"docstring": None,
"unique_together": [["chars", "blip"]],
"indexes": [],
"pk_field": {
"name": "eyedee",
"field_type": fields.IntField,
Expand Down Expand Up @@ -585,6 +587,7 @@ def test_describe_model_source(self):
"description": "Source mapped fields",
"docstring": "A Docstring.",
"unique_together": [["chars", "blip"]],
"indexes": [],
"pk_field": {
"name": "eyedee",
"field_type": "IntField",
Expand Down Expand Up @@ -804,6 +807,7 @@ def test_describe_model_source_native(self):
"description": "Source mapped fields",
"docstring": "A Docstring.",
"unique_together": [["chars", "blip"]],
"indexes": [],
"pk_field": {
"name": "eyedee",
"field_type": fields.IntField,
Expand Down Expand Up @@ -1024,6 +1028,7 @@ def test_describe_model_uuidpk(self):
"description": None,
"docstring": None,
"unique_together": [],
"indexes": [],
"pk_field": {
"name": "id",
"field_type": "UUIDField",
Expand Down Expand Up @@ -1097,6 +1102,7 @@ def test_describe_model_uuidpk_native(self):
"description": None,
"docstring": None,
"unique_together": [],
"indexes": [],
"pk_field": {
"name": "id",
"field_type": fields.UUIDField,
Expand Down Expand Up @@ -1272,6 +1278,7 @@ def test_describe_model_uuidpk_relatednull(self):
},
"table": "uuidfkrelatednullmodel",
"unique_together": [],
"indexes": [],
},
)

Expand All @@ -1288,6 +1295,7 @@ def test_describe_model_json(self):
"description": "This model contains many JSON blobs",
"docstring": "This model contains many JSON blobs",
"unique_together": [],
"indexes": [],
"pk_field": {
"name": "id",
"field_type": "IntField",
Expand Down Expand Up @@ -1386,6 +1394,7 @@ def test_describe_model_json_native(self):
"description": "This model contains many JSON blobs",
"docstring": "This model contains many JSON blobs",
"unique_together": [],
"indexes": [],
"pk_field": {
"name": "id",
"field_type": fields.IntField,
Expand Down
1 change: 1 addition & 0 deletions tortoise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,7 @@ def describe(cls, serializable: bool = True) -> dict:
"description": cls._meta.table_description or None,
"docstring": inspect.cleandoc(cls.__doc__ or "") or None,
"unique_together": cls._meta.unique_together or [],
"indexes": cls._meta.indexes or [],
"pk_field": cls._meta.fields_map[cls._meta.pk_attr].describe(serializable),
"data_fields": [
field.describe(serializable)
Expand Down

0 comments on commit af5d87e

Please sign in to comment.