Skip to content

Commit

Permalink
Change line numbers in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mekanix committed Feb 12, 2024
1 parent 27d798c commit 358f4ce
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 91 deletions.
2 changes: 1 addition & 1 deletion docs/fields/common-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Used in sql only.

Sample usage:

```Python hl_lines="21-23"
```Python hl_lines="20-22"
--8<-- "../docs_src/fields/docs004.py"
```

Expand Down
37 changes: 19 additions & 18 deletions docs/models/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ They are being managed in the background and you do not have to create them on y

To build an ormar model you simply need to inherit a `ormar.Model` class.

```Python hl_lines="10"
```Python hl_lines="9"
--8<-- "../docs_src/models/docs001.py"
```

Expand All @@ -23,7 +23,7 @@ Each table **has to** have a primary key column, which you specify by setting `p

Only one primary key column is allowed.

```Python hl_lines="15 16 17"
```Python hl_lines="15-17"
--8<-- "../docs_src/models/docs001.py"
```

Expand Down Expand Up @@ -60,7 +60,7 @@ you should get back exactly same value in `response`.).
!!!warning
pydantic fields have to be always **Optional** and it cannot be changed (otherwise db load validation would fail)

```Python hl_lines="18"
```Python hl_lines="19"
--8<-- "../docs_src/models/docs014.py"
```

Expand Down Expand Up @@ -134,17 +134,17 @@ If for whatever reason you prefer to change the name in the database but keep th
with specifying `name` parameter during Field declaration

Here you have a sample model with changed names
```Python hl_lines="16-19"
```Python hl_lines="18-21"
--8<-- "../docs_src/models/docs008.py"
```

Note that you can also change the ForeignKey column name
```Python hl_lines="21"
```Python hl_lines="34"
--8<-- "../docs_src/models/docs009.py"
```

But for now you cannot change the ManyToMany column names as they go through other Model anyway.
```Python hl_lines="28"
```Python hl_lines="43"
--8<-- "../docs_src/models/docs010.py"
```

Expand Down Expand Up @@ -219,7 +219,7 @@ One is `Database` instance created with your database url in [sqlalchemy connect

Created instance needs to be passed to every `Model` with `Meta` class `database` parameter.

```Python hl_lines="1 6 12"
```Python hl_lines="1 5 11"
--8<-- "../docs_src/models/docs001.py"
```

Expand All @@ -233,7 +233,7 @@ Second dependency is sqlalchemy `MetaData` instance.

Created instance needs to be passed to every `Model` with `Meta` class `metadata` parameter.

```Python hl_lines="2 7 13"
```Python hl_lines="3 6 12"
--8<-- "../docs_src/models/docs001.py"
```

Expand All @@ -243,11 +243,12 @@ Created instance needs to be passed to every `Model` with `Meta` class `metadata

#### Best practice

Only thing that `ormar` expects is a class with name `Meta` and two class variables: `metadata` and `databases`.
Only thing that `ormar` expects is a field with name `ormar_config`.

So instead of providing the same parameters over and over again for all models you should creata a class and subclass it in all models.
So instead of providing the same parameters over and over again for all models
you should creat an object and use its copy in all models.

```Python hl_lines="14 20 33"
```Python hl_lines="9-11 18 27"
--8<-- "../docs_src/models/docs013.py"
```

Expand All @@ -261,7 +262,7 @@ By default table name is created from Model class name as lowercase name plus 's

You can overwrite this parameter by providing `Meta` class `tablename` argument.

```Python hl_lines="12 13 14"
```Python hl_lines="14-16"
--8<-- "../docs_src/models/docs002.py"
```

Expand All @@ -281,7 +282,7 @@ Right now only `IndexColumns` and `UniqueColumns` constraints are supported.

You can set this parameter by providing `Meta` class `constraints` argument.

```Python hl_lines="14-17"
```Python hl_lines="13-16"
--8<-- "../docs_src/models/docs006.py"
```

Expand All @@ -294,7 +295,7 @@ You can set this parameter by providing `Meta` class `constraints` argument.

You can set this parameter by providing `Meta` class `constraints` argument.

```Python hl_lines="14-17"
```Python hl_lines="13-16"
--8<-- "../docs_src/models/docs017.py"
```

Expand All @@ -307,7 +308,7 @@ You can set this parameter by providing `Meta` class `constraints` argument.

You can set this parameter by providing `Meta` class `constraints` argument.

```Python hl_lines="14-17"
```Python hl_lines="15-20"
--8<-- "../docs_src/models/docs018.py"
```

Expand Down Expand Up @@ -336,7 +337,7 @@ class Config(pydantic.BaseConfig):
```

So to overwrite setting or provide your own a sample model can look like following:
```Python hl_lines="15-16"
```Python hl_lines="16"
--8<-- "../docs_src/models/docs016.py"
```

Expand Down Expand Up @@ -425,7 +426,7 @@ There are two ways to create and persist the `Model` instance in the database.

If you plan to modify the instance in the later execution of your program you can initiate your `Model` as a normal class and later await a `save()` call.

```Python hl_lines="20 21"
```Python hl_lines="25-26"
--8<-- "../docs_src/models/docs007.py"
```

Expand All @@ -435,7 +436,7 @@ For creating multiple objects at once a `bulk_create()` QuerySet's method is ava

Each model has a `QuerySet` initialised as `objects` parameter

```Python hl_lines="23"
```Python hl_lines="28"
--8<-- "../docs_src/models/docs007.py"
```

Expand Down
4 changes: 2 additions & 2 deletions docs/models/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ To access auto created sqlalchemy table you can use `Model.Meta.table` parameter

For example to list table columns you can:

```Python hl_lines="20"
```Python hl_lines="24"
--8<-- "../docs_src/models/docs004.py"
```

Expand All @@ -40,7 +40,7 @@ To access ormar `Fields` you can use `Model.Meta.model_fields` parameter

For example to list table model fields you can:

```Python hl_lines="20"
```Python hl_lines="22"
--8<-- "../docs_src/models/docs005.py"
```

Expand Down
4 changes: 2 additions & 2 deletions docs/queries/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ assert album == album2

Updates the model, or in case there is no match in database creates a new one.

```Python hl_lines="26-32"
```Python hl_lines="40-48"
--8<-- "../docs_src/queries/docs003.py"
```

Expand All @@ -122,7 +122,7 @@ Allows you to create multiple objects at once.

A valid list of `Model` objects needs to be passed.

```python hl_lines="21-27"
```python hl_lines="26-32"
--8<-- "../docs_src/queries/docs004.py"
```

Expand Down
4 changes: 2 additions & 2 deletions docs/queries/delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ If you do not provide this flag or a filter a `QueryDefinitionError` will be rai

Return number of rows deleted.

```python hl_lines="26-30"
```python hl_lines="40-44"
--8<-- "../docs_src/queries/docs005.py"
```

Expand Down Expand Up @@ -148,4 +148,4 @@ await album.tracks.clear()
await album.tracks.clear(keep_reversed=False)
```

[querysetproxy]: ../relations/queryset-proxy.md
[querysetproxy]: ../relations/queryset-proxy.md
6 changes: 3 additions & 3 deletions docs/queries/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ If you do not provide this flag or a filter a `QueryDefinitionError` will be rai

Return number of rows updated.

```Python hl_lines="26-28"
```Python hl_lines="42-44"
--8<-- "../docs_src/queries/docs002.py"
```

Expand All @@ -44,7 +44,7 @@ Return number of rows updated.

Updates the model, or in case there is no match in database creates a new one.

```Python hl_lines="26-32"
```Python hl_lines="40-48"
--8<-- "../docs_src/queries/docs003.py"
```

Expand Down Expand Up @@ -123,4 +123,4 @@ from other side of the relation.

[querysetproxy]: ../relations/queryset-proxy.md
[models-upsert]: ../models/methods.md#upsert
[models-save-related]: ../models/methods.md#save_related
[models-save-related]: ../models/methods.md#save_related
16 changes: 8 additions & 8 deletions docs/relations/foreign-key.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Sqlalchemy column and Type are automatically taken from target `Model`.

To define a relation add `ForeignKey` field that points to related `Model`.

```Python hl_lines="29"
```Python hl_lines="30"
--8<-- "../docs_src/fields/docs003.py"
```

Expand All @@ -24,7 +24,7 @@ To define a relation add `ForeignKey` field that points to related `Model`.

By default it's child (source) `Model` name + s, like courses in snippet below:

```Python hl_lines="29 35"
```Python hl_lines="29 36"
--8<-- "../docs_src/fields/docs001.py"
```

Expand Down Expand Up @@ -175,7 +175,7 @@ To read which methods of QuerySet are available read below [querysetproxy][query

But you can overwrite this name by providing `related_name` parameter like below:

```Python hl_lines="29 35"
```Python hl_lines="27-29 35"
--8<-- "../docs_src/fields/docs002.py"
```

Expand Down Expand Up @@ -230,15 +230,15 @@ You have several ways to set-up a relationship connection.

The most obvious one is to pass a related `Model` instance to the constructor.

```Python hl_lines="34-35"
```Python hl_lines="35-36"
--8<-- "../docs_src/relations/docs001.py"
```

### Primary key value

You can setup the relation also with just the pk column value of the related model.

```Python hl_lines="37-38"
```Python hl_lines="38-39"
--8<-- "../docs_src/relations/docs001.py"
```

Expand All @@ -248,15 +248,15 @@ Next option is with a dictionary of key-values of the related model.

You can build the dictionary yourself or get it from existing model with `model_dump()` method.

```Python hl_lines="40-41"
```Python hl_lines="41-42"
--8<-- "../docs_src/relations/docs001.py"
```

### None

Finally you can explicitly set it to None (default behavior if no value passed).

```Python hl_lines="43-44"
```Python hl_lines="44-45"
--8<-- "../docs_src/relations/docs001.py"
```

Expand All @@ -283,4 +283,4 @@ Finally you can explicitly set it to None (default behavior if no value passed).
[fields]: ./queries.md#fields
[exclude_fields]: ./queries.md#exclude_fields
[order_by]: ./queries.md#order_by
[server_default]: ../fields/common-parameters.md#server-default
[server_default]: ../fields/common-parameters.md#server-default
Loading

0 comments on commit 358f4ce

Please sign in to comment.