File: many_to_many.py

package info (click to toggle)
python-odmantic 1.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,488 kB
  • sloc: python: 8,646; sh: 110; javascript: 45; makefile: 34; xml: 13
file content (30 lines) | stat: -rw-r--r-- 606 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from typing import List

from bson import ObjectId

from odmantic import AIOEngine, Model


class Author(Model):
    name: str


class Book(Model):
    title: str
    pages: int
    author_ids: List[ObjectId]


david = Author(name="David Beazley")
brian = Author(name="Brian K. Jones")

python_cookbook = Book(
    title="Python Cookbook", pages=706, author_ids=[david.id, brian.id]
)
python_essentials = Book(
    title="Python Essential Reference", pages=717, author_ids=[brian.id]
)

engine = AIOEngine()
await engine.save_all((david, brian))
await engine.save_all((python_cookbook, python_essentials))