()
| 22 | |
| 23 | |
| 24 | async def run(): |
| 25 | await Tortoise.init(db_url="sqlite://:memory:", modules={"models": ["__main__"]}) |
| 26 | await Tortoise.generate_schemas() |
| 27 | |
| 28 | obj0 = await EnumFields.create(service=Service.python_programming, currency=Currency.USD) |
| 29 | # also you can use valid int and str value directly |
| 30 | await EnumFields.create(service=1, currency="USD") |
| 31 | |
| 32 | try: |
| 33 | # invalid enum value will raise ValueError |
| 34 | await EnumFields.create(service=4, currency="XXX") |
| 35 | except ValueError: |
| 36 | print("Value is invalid") |
| 37 | |
| 38 | await EnumFields.filter(pk=obj0.pk).update( |
| 39 | service=Service.database_design, currency=Currency.HUF |
| 40 | ) |
| 41 | # also you can use valid int and str value directly |
| 42 | await EnumFields.filter(pk=obj0.pk).update(service=2, currency="HUF") |
| 43 | |
| 44 | |
| 45 | if __name__ == "__main__": |
no test coverage detected