File: compound_index.py

package info (click to toggle)
python-odmantic 1.0.2-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,640 kB
  • sloc: python: 8,547; sh: 37; makefile: 34; xml: 13; javascript: 3
file content (15 lines) | stat: -rw-r--r-- 370 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from odmantic import Field, Index, Model


class Product(Model):
    name: str = Field(index=True)
    stock: int
    category: str
    sku: str = Field(unique=True)

    model_config = {
        "indexes": lambda: [
            Index(Product.name, Product.stock, name="name_stock_index"),
            Index(Product.name, Product.category, unique=True),
        ]
    }