File: views.py

package info (click to toggle)
python-beanie 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,480 kB
  • sloc: python: 14,427; makefile: 7; sh: 6
file content (25 lines) | stat: -rw-r--r-- 686 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
from beanie.odm.fields import Link
from beanie.odm.views import View
from tests.odm.models import DocumentTestModel, DocumentTestModelWithLink


class ViewForTest(View):
    number: int
    string: str

    class Settings:
        view_name = "test_view"
        source = DocumentTestModel
        pipeline = [
            {"$match": {"$expr": {"$gt": ["$test_int", 8]}}},
            {"$project": {"number": "$test_int", "string": "$test_str"}},
        ]


class ViewForTestWithLink(View):
    link: Link[DocumentTestModel]

    class Settings:
        view_name = "test_view_with_link"
        source = DocumentTestModelWithLink
        pipeline = [{"$set": {"link": "$test_link"}}]