Sör*_*ifé 5 python django orm asynchronous
最近Django 4.1发布了一个新的异步 ORM 接口。这个真的很酷。但我已经使用它几周了,我发现了一个让我陷入困境的用例。
\n我试图在异步上下文中复制此行为:
\nclass Foo(m.Model):\n """\n Stores information about a Foo\n """\n name: Union[m.CharField, str] = m.CharField(max_length=49)\n\n\nfoo: Foo = Foo(name=\'bar\')\nfoo.save()\n
Run Code Online (Sandbox Code Playgroud)\n首先,该acreate()
方法并不能解决我的问题。我需要首先创建模型实例,然后保存它。
\n我的猜测方法 - 与 ORM 接口一致 - 是使用foo.asave()
但该方法不存在。
我正在尝试找到一种更干净的方法来解决这个问题,而不是使用sync_to_async方法。
\n非常感谢您的帮助!\xe2\x9d\xa4\xef\xb8\x8f
\n 归档时间: |
|
查看次数: |
811 次 |
最近记录: |