@@ -53,15 +53,15 @@ notes = await Note.objects.filter(completed=True).all()
53
53
54
54
There are some special operators defined automatically on every column:
55
55
56
- * ` in ` - SQL ` IN ` operator.
57
- * ` exact ` - filter instances matching exact value.
58
- * ` iexact ` - same as ` exact ` but case-insensitive.
59
- * ` contains ` - filter instances containing value.
60
- * ` icontains ` - same as ` contains ` but case-insensitive.
61
- * ` lt ` - filter instances having value ` Less Than ` .
62
- * ` lte ` - filter instances having value ` Less Than Equal ` .
63
- * ` gt ` - filter instances having value ` Greater Than ` .
64
- * ` gte ` - filter instances having value ` Greater Than Equal ` .
56
+ - ` in ` - SQL ` IN ` operator.
57
+ - ` exact ` - filter instances matching exact value.
58
+ - ` iexact ` - same as ` exact ` but case-insensitive.
59
+ - ` contains ` - filter instances containing value.
60
+ - ` icontains ` - same as ` contains ` but case-insensitive.
61
+ - ` lt ` - filter instances having value ` Less Than ` .
62
+ - ` lte ` - filter instances having value ` Less Than Equal ` .
63
+ - ` gt ` - filter instances having value ` Greater Than ` .
64
+ - ` gte ` - filter instances having value ` Greater Than Equal ` .
65
65
66
66
Example usage:
67
67
@@ -84,7 +84,7 @@ notes = await Note.objects.filter(Note.columns.id.in_([1, 2, 3])).all()
84
84
Here ` Note.columns ` refers to the columns of the underlying SQLAlchemy table.
85
85
86
86
!!! note
87
- Note that ` Note.columns ` returns SQLAlchemy table columns, whereas ` Note.fields ` returns ` orm ` fields.
87
+ Note that ` Note.columns ` returns SQLAlchemy table columns, whereas ` Note.fields ` returns ` orm ` fields.
88
88
89
89
### .limit()
90
90
@@ -119,7 +119,7 @@ notes = await Note.objects.order_by("text", "-id").all()
119
119
```
120
120
121
121
!!! note
122
- This will sort by ascending ` text ` and descending ` id ` .
122
+ This will sort by ascending ` text ` and descending ` id ` .
123
123
124
124
## Returning results
125
125
@@ -146,10 +146,10 @@ await Note.objects.create(text="Send invoices.", completed=True)
146
146
You need to pass a list of dictionaries of required fields to create multiple objects:
147
147
148
148
``` python
149
- await Product .objects.bulk_create(
149
+ await Note .objects.bulk_create(
150
150
[
151
- {" data " : { " foo " : 123 }, " value " : 123.456 , " status " : StatusEnum. RELEASED },
152
- {" data " : { " foo " : 456 }, " value " : 456.789 , " status " : StatusEnum. DRAFT },
151
+ {" text " : " Buy the groceries " , " completed " : False },
152
+ {" text " : " Call Mum. " , " completed " : True },
153
153
154
154
]
155
155
)
@@ -209,7 +209,7 @@ note = await Note.objects.get(id=1)
209
209
```
210
210
211
211
!!! note
212
- ` .get() ` expects to find only one instance. This can raise ` NoMatch ` or ` MultipleMatches ` .
212
+ ` .get() ` expects to find only one instance. This can raise ` NoMatch ` or ` MultipleMatches ` .
213
213
214
214
### .update()
215
215
@@ -233,6 +233,18 @@ note = await Note.objects.first()
233
233
await note.update(completed = True )
234
234
```
235
235
236
+ ### .bulk_update()
237
+
238
+ You can also bulk update multiple objects at once by passing a list of objects and a list of fields to update.
239
+
240
+ ``` python
241
+ notes = await Note.objects.all()
242
+ for note in notes :
243
+ note.completed = True
244
+
245
+ await Note.objects.bulk_update(notes, fields = [" completed" ])
246
+ ```
247
+
236
248
## Convenience Methods
237
249
238
250
### .get_or_create()
@@ -250,8 +262,7 @@ This will query a `Note` with `text` as `"Going to car wash"`,
250
262
if it doesn't exist, it will use ` defaults ` argument to create the new instance.
251
263
252
264
!!! note
253
- Since ` get_or_create() ` is doing a [ get()] ( #get ) , it can raise ` MultipleMatches ` exception.
254
-
265
+ Since ` get_or_create() ` is doing a [ get()] ( #get ) , it can raise ` MultipleMatches ` exception.
255
266
256
267
### .update_or_create()
257
268
@@ -269,4 +280,4 @@ if an instance is found, it will use the `defaults` argument to update the insta
269
280
If it matches no records, it will use the comibnation of arguments to create the new instance.
270
281
271
282
!!! note
272
- Since ` update_or_create() ` is doing a [ get()] ( #get ) , it can raise ` MultipleMatches ` exception.
283
+ Since ` update_or_create() ` is doing a [ get()] ( #get ) , it can raise ` MultipleMatches ` exception.
0 commit comments