是否有信号或任何类似于“pre_select”的信号?在 Django 中?
我正在 django 中创建一个系统,每次在数据库上执行 SQL“选择”查询时调用一个信号会非常有帮助。换句话说,有谁知道是否有类似“pre_select”或“post_select”信号方法?
我在 django 文档中找到了信号“connection_created”,但找不到任何有关如何使用它的线索,也找不到有关访问调用它的模型的线索。官方文档只是说它存在,但没有给出简单的使用示例... =/
编辑: Connection_created 仅在创建连接时起作用(如其名称所示),因此,我仍然没有解决方案=/。
我想要的一个例子是在不同的对象上执行此查询:
ExampleObject1.objects.filter(attribute=somevalue)
ExampleObject2.objects.filter(attribute=somevalue)
ExampleObject3.objects.filter(attribute=somevalue)
因此,在每个查询发送到数据库之前,调用一个函数来接收来自每个对象的数据,以威胁数据、日志等。 我想 django 中存在一些类似的功能,因为 django 日志系统似乎使用类似的东西。
欢迎任何帮助。提前致谢!
I'm creating a system in django and it'd be really helpful to have a signal that is called every time a SQL "select" query is done on the database. In other words, does anyone know if there is something like a "pre_select" or "post_select" signal method?
I found the signal "connection_created" in the django docs, but couldn't find any clues of how to use it and less about accessing the model that called it. The official documentation just say that it exists but don't give a simple using example... =/
EDIT:
The connection_created just works when the connection is created (how its name says), so, I still without a solution =/.
An example of what I want would be the execution of this queries on distinct objects:
ExampleObject1.objects.filter(attribute=somevalue)
ExampleObject2.objects.filter(attribute=somevalue)
ExampleObject3.objects.filter(attribute=somevalue)
So a function is called receiving the data from each them just before each query being sent to the database in order to threat data, log, etc.
I imagine that exists some functionality like that in django because django log system appears to use something alike.
Any help is welcome. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 http://dabapps.com/blog/logging-sql-queries-django -13/
它不是信号的形式,但它允许您跟踪所有查询。通过提供定制的日志处理程序应该可以跟踪特定的选择。
From http://dabapps.com/blog/logging-sql-queries-django-13/
It's not in the form of signal, but it allows you to track all queries. Tracking specific selects should be doable by providing customized log handlers.