class Organisation(ormar.Model):
    class Meta:
        tablename = "org"
        metadata = metadata
        database = database

    id: int = ormar.Integer(primary_key=True)
    ident: str = ormar.String(max_length=100,
                              choices=["ACME Ltd", "Other ltd"])
    priority: int = ormar.Integer(choices=[1, 2, 3, 4, 5])
    priority2: int = ormar.BigInteger(choices=[1, 2, 3, 4, 5])
    expire_date: datetime.date = ormar.Date(
        choices=[datetime.date(2021, 1, 1),
                 datetime.date(2022, 5, 1)])
    expire_time: datetime.time = ormar.Time(
        choices=[datetime.time(10, 0, 0),
                 datetime.time(12, 30)])

    expire_datetime: datetime.datetime = ormar.DateTime(choices=[
        datetime.datetime(2021, 1, 1, 10, 0, 0),
        datetime.datetime(2022, 5, 1, 12, 30),
    ])
    random_val: float = ormar.Float(choices=[2.0, 3.5])
    random_decimal: decimal.Decimal = ormar.Decimal(
        scale=2,
        precision=4,
        choices=[decimal.Decimal(12.4),
                 decimal.Decimal(58.2)])
    random_json: pydantic.Json = ormar.JSON(choices=["aa", '{"aa":"bb"}'])
    random_uuid: uuid.UUID = ormar.UUID(choices=[uuid1, uuid2])
    enum_string: str = ormar.String(max_length=100, choices=list(EnumTest))
class Author(ormar.Model):
    class Meta(BaseMeta):
        tablename = "authors"

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=100, **default_fernet)
    uuid_test = ormar.UUID(default=uuid.uuid4, uuid_format="string")
    uuid_test2 = ormar.UUID(nullable=True, uuid_format="string")
    password: str = ormar.String(
        max_length=128,
        encrypt_secret="udxc32",
        encrypt_backend=ormar.EncryptBackends.HASH,
    )
    birth_year: int = ormar.Integer(
        nullable=True,
        encrypt_secret="secure89key%^&psdijfipew",
        encrypt_backend=ormar.EncryptBackends.FERNET,
    )
    test_text: str = ormar.Text(default="", **default_fernet)
    test_bool: bool = ormar.Boolean(nullable=False, **default_fernet)
    test_float: float = ormar.Float(**default_fernet)
    test_float2: float = ormar.Float(nullable=True, **default_fernet)
    test_datetime = ormar.DateTime(default=datetime.datetime.now, **default_fernet)
    test_date = ormar.Date(default=datetime.date.today, **default_fernet)
    test_time = ormar.Time(default=datetime.time, **default_fernet)
    test_json = ormar.JSON(default={}, **default_fernet)
    test_bigint: int = ormar.BigInteger(default=0, **default_fernet)
    test_decimal = ormar.Decimal(scale=2, precision=10, **default_fernet)
    test_decimal2 = ormar.Decimal(max_digits=10, decimal_places=2, **default_fernet)
    custom_backend: str = ormar.String(
        max_length=200,
        encrypt_secret="asda8",
        encrypt_backend=ormar.EncryptBackends.CUSTOM,
        encrypt_custom_backend=DummyBackend,
    )
Beispiel #3
0
class Invoice(ormar.Model):
    class Meta(BaseMeta):
        tablename = "invoice"

    id = ormar.Integer(primary_key=True)
    invoice_business_id = ormar.String(max_length=64)
    invoice_date = ormar.Date()
    invoice_type = ormar.String(max_length=8, choices=[])
    trading_partner_id = ormar.ForeignKey(TradingPartner)
    enterprise_id = ormar.ForeignKey(Enterprise, ondelete="CASCADE")
Beispiel #4
0
class Product(ormar.Model):
    class Meta:
        tablename = "product"
        metadata = metadata
        database = database

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=100)
    rating: int = ormar.Integer(minimum=1, maximum=5)
    in_stock: bool = ormar.Boolean(default=False)
    last_delivery: datetime.date = ormar.Date(default=datetime.datetime.now)
Beispiel #5
0
class Example(ormar.Model):
    class Meta:
        tablename = "example"
        metadata = metadata
        database = database

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=200, default="aaa")
    created: datetime.datetime = ormar.DateTime(default=datetime.datetime.now)
    created_day: datetime.date = ormar.Date(default=datetime.date.today)
    created_time: datetime.time = ormar.Time(default=time)
    description: str = ormar.Text(nullable=True)
    value: float = ormar.Float(nullable=True)
    data: pydantic.Json = ormar.JSON(default={})
Beispiel #6
0
class ExampleModel(Model):
    class Meta:
        tablename = "example"
        metadata = metadata

    test: int = ormar.Integer(primary_key=True)
    test_string: str = ormar.String(max_length=250)
    test_text: str = ormar.Text(default="")
    test_bool: bool = ormar.Boolean(nullable=False)
    test_float: ormar.Float() = None  # type: ignore
    test_datetime = ormar.DateTime(default=datetime.datetime.now)
    test_date = ormar.Date(default=datetime.date.today)
    test_time = ormar.Time(default=datetime.time)
    test_json = ormar.JSON(default={})
    test_bigint: int = ormar.BigInteger(default=0)
    test_decimal = ormar.Decimal(scale=2, precision=10)
    test_decimal2 = ormar.Decimal(max_digits=10, decimal_places=2)