如何为 Django 创建 ltree 数据类型?

发布于 2024-09-30 14:25:33 字数 473 浏览 1 评论 0原文

如何为 Django 创建 Postgres ltree 数据类型?以及如何将它与 QuerySet 一起使用? (创建包装器?如何?)

关于 lree 这里: http://www.postgresql.org/docs/current/static/ltree.html

关于 Django 中的自定义字段: docs.djangoproject.com/en/1.2/howto/custom-model-fields/

PS 还有 "Django Tree Libraries" 但 ltree 看起来更好..

How to create Postgres ltree data type for Django? and how to use it with QuerySets? (create wrapper? how?)

About lree here:
http://www.postgresql.org/docs/current/static/ltree.html

About custom fields in Django here:
docs.djangoproject.com/en/1.2/howto/custom-model-fields/

P.S.
Also there are "Django Tree Libraries" but ltree looks better..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月隐月明月朦胧 2024-10-07 14:25:33

django-ltree 为您管理集成。它还具有在数据库中添加 ltree 扩展的迁移。

There is django-ltree that manages the integration for you. It also has the migrations to add the ltree extension in your database.

呆° 2024-10-07 14:25:33

您列出了两个正确的部分。将 PostgreSQL 数据类型适配到 Django 的一般方法是:

  1. 创建一个表示该数据类型的新 Python 类。
  2. 向 psycopg2 注册该数据类型,以便 psycopg2 了解如何使其适应数据库。

有关步骤 2 的文档位于 http://initd.org/psycopg/ docs/advanced.html#adapting-new-types ...

You have listed two of the correct pieces. The general method for adapting a PostgreSQL data type to Django is:

  1. Create a new Python class that represents the data type.
  2. Register that data type with psycopg2 so that psycopg2 understands how adapt it to the database.

Documentation on step 2 is available at http://initd.org/psycopg/docs/advanced.html#adapting-new-types ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文