You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.6 KiB
65 lines
1.6 KiB
2 weeks ago
|
from tortoise import Tortoise, run_async
|
||
|
import asyncio
|
||
|
import json
|
||
|
import os
|
||
|
|
||
|
|
||
|
async def init():
|
||
|
# Here we create a SQLite DB using file "db.sqlite3"
|
||
|
# also specify the app name of "models"
|
||
|
# which contain models from "app.models"
|
||
|
await Tortoise.init(
|
||
|
config={
|
||
|
"connections": {
|
||
|
"default": "mysql://root:123456@127.0.0.1:3306/agv?charset=utf8mb4"
|
||
|
},
|
||
|
"apps": {
|
||
|
"models": {
|
||
|
"models": ["aerich.models", "models"],
|
||
|
"default_connection": "default"
|
||
|
}
|
||
|
},
|
||
|
'use_tz': False,
|
||
|
# 'timezone': setting.TIMEZONE
|
||
|
}
|
||
|
)
|
||
|
# Generate the schema
|
||
|
# await Tortoise.generate_schemas()
|
||
|
|
||
|
# run_async is a helper function to run simple async Tortoise scripts.
|
||
|
run_async(init())
|
||
|
|
||
|
from models.warehouse import Hole, Vacancy
|
||
|
|
||
|
|
||
|
async def clearHoles():
|
||
|
holes = await Hole.all().filter(is_active = True)
|
||
|
for hole in holes:
|
||
|
hole.is_active = False
|
||
|
await hole.save()
|
||
|
|
||
|
|
||
|
async def main():
|
||
|
qs = await Vacancy.all() \
|
||
|
.order_by("-is_connect") \
|
||
|
.distinct()
|
||
|
print("qs: ", qs)
|
||
|
for vac in qs:
|
||
|
print("vac ", vac)
|
||
|
|
||
|
vacancy = await Vacancy.get_or_none(number = "Left", is_active = True)
|
||
|
|
||
|
if vacancy:
|
||
|
await vacancy.fetch_related("holes")
|
||
|
holes = await vacancy.holes
|
||
|
print("holes: ", holes)
|
||
|
|
||
|
await vacancy.holes.clear()
|
||
|
|
||
|
await clearHoles()
|
||
|
print("Hole: ", await Hole.all().filter(is_active = True))
|
||
|
|
||
|
asyncio.run( main() )
|
||
|
|
||
|
exit()
|