You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -152,7 +154,7 @@ But for now you cannot change the ManyToMany column names as they go through oth
152
154
--8<--"../docs_src/models/docs010.py"
153
155
```
154
156
155
-
## Overwriting the default QuerySet
157
+
###Overwriting the default QuerySet
156
158
157
159
If you want to customize the queries run by ormar you can define your own queryset class (that extends the ormar `QuerySet`) in your model class, default one is simply the `QuerySet`
158
160
@@ -188,9 +190,9 @@ book = await Book.objects.first_or_404(name="123")
188
190
189
191
```
190
192
191
-
### Type Hints & Legacy
193
+
### Type Hints
192
194
193
-
From version >=0.4.0 `ormar` switched to new notation.
195
+
Note that for better IDE support and mypy checks you can provide type hints.
194
196
195
197
```Python hl_lines="15-17"
196
198
--8<--"../docs_src/models/docs001.py"
@@ -245,20 +247,20 @@ Created instance needs to be passed to every `Model` with `ormar_config` object
245
247
246
248
#### Best practice
247
249
248
-
Only thing that `ormar` expects is a field with name `ormar_config`.
249
-
250
+
Note that `ormar` expects the field with name `ormar_config` that is an instance of `OrmarConfig` class.
251
+
To ease the config management, the `OrmarConfig` class provide `copy` method.
250
252
So instead of providing the same parameters over and over again for all models
251
-
you should creat an object and use its copy in all models.
253
+
you should create a base object and use its copy in all models.
252
254
253
-
```Python hl_lines="9-11 18 27"
255
+
```Python hl_lines="9-12 19 28"
254
256
--8<--"../docs_src/models/docs013.py"
255
257
```
256
258
257
259
### Table Names
258
260
259
261
By default table name is created from Model class name as lowercase name plus 's'.
260
262
261
-
You can overwrite this parameter by providing `ormar_config` object `tablename` argument.
263
+
You can overwrite this parameter by providing `ormar_config` object's`tablename` argument.
262
264
263
265
```Python hl_lines="14-16"
264
266
--8<--"../docs_src/models/docs002.py"
@@ -268,10 +270,10 @@ You can overwrite this parameter by providing `ormar_config` object `tablename`
268
270
269
271
On a model level you can also set model-wise constraints on sql columns.
270
272
271
-
Right now only `IndexColumns`and `UniqueColumns` constraints are supported.
273
+
Right now only `IndexColumns`, `UniqueColumns`and `CheckColumns` constraints are supported.
272
274
273
275
!!!note
274
-
Note that both constraints should be used only if you want to set a name on constraint or want to set the index on multiple columns, otherwise `index` and `unique` properties on ormar fields are preferred.
276
+
Note that both constraints should be used only if you want to set a name on constraint or want to set the index on multiple columns, otherwise `index` and `unique` properties on ormar fields are preferred.
275
277
276
278
!!!tip
277
279
To read more about columns constraints like `primary_key`, `unique`, `ForeignKey` etc. visit [fields][fields].
@@ -285,9 +287,9 @@ You can set this parameter by providing `ormar_config` object `constraints` argu
285
287
```
286
288
287
289
!!!note
288
-
Note that constraints are meant for combination of columns that should be unique.
289
-
To set one column as unique use [`unique`](../fields/common-parameters.md#unique) common parameter.
290
-
Of course you can set many columns as unique with this param but each of them will be checked separately.
290
+
Note that constraints are meant for combination of columns that should be unique.
291
+
To set one column as unique use [`unique`](../fields/common-parameters.md#unique) common parameter.
292
+
Of course you can set many columns as unique with this param but each of them will be checked separately.
291
293
292
294
#### IndexColumns
293
295
@@ -298,9 +300,9 @@ You can set this parameter by providing `ormar_config` object `constraints` argu
298
300
```
299
301
300
302
!!!note
301
-
Note that constraints are meant for combination of columns that should be in the index.
302
-
To set one column index use [`unique`](../fields/common-parameters.md#index) common parameter.
303
-
Of course, you can set many columns as indexes with this param but each of them will be a separate index.
303
+
Note that constraints are meant for combination of columns that should be in the index.
304
+
To set one column index use [`unique`](../fields/common-parameters.md#index) common parameter.
305
+
Of course, you can set many columns as indexes with this param but each of them will be a separate index.
304
306
305
307
#### CheckColumns
306
308
@@ -311,7 +313,7 @@ You can set this parameter by providing `ormar_config` object `constraints` argu
311
313
```
312
314
313
315
!!!note
314
-
Note that some databases do not actively support check constraints such as MySQL.
316
+
Note that some databases do not actively support check constraints (such as MySQL).
315
317
316
318
317
319
### Pydantic configuration
@@ -323,13 +325,13 @@ The way to do this in pydantic is to adjust the settings on the `model_config` d
323
325
So in order to set your own preferences you need to provide not only the `ormar_config` class but also the `model_config = ConfigDict()` class to your model.
324
326
325
327
!!!note
326
-
To read more about available settings visit the [pydantic](https://pydantic-docs.helpmanual.io/usage/model_config/) config page.
328
+
To read more about available settings visit the [pydantic](https://pydantic-docs.helpmanual.io/usage/model_config/) config page.
327
329
328
330
Note that if you do not provide your own configuration, ormar will do it for you.
There are two ways to create and persist the `Model` instance in the database.
412
416
413
-
!!!tip
414
-
Use `ipython` to try this from the console, since it supports `await`.
415
-
416
417
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.
0 commit comments