如何在 Django ORM 中映射 PostgreSQL 数组字段 [英] How to map PostgreSQL array field in Django ORM

查看:34
本文介绍了如何在 Django ORM 中映射 PostgreSQL 数组字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 PostrgreSQL 数据库中有一个 array 字段,文本类型.有没有办法将其映射到 Django 模型中?

I have an array field in my PostrgreSQL database of type text. Is there a way to map this into a Django model ?

推荐答案

你可能想看看 django-dbarray在github上.它增加了对 postgresql 数组字段的支持.

You might want to look into django-dbarray on github. It adds support for postgresql array fields.

我以前没用过,但看起来你只需要这样做:

I haven't used it before, but it looks like you just need to do:

from django.db import model
import dbarray

class ProfilingTestRun(models.Model):
    function = models.CharField(max_length=64)
    runtimes = dbarray.FloatArrayField()

这篇关于如何在 Django ORM 中映射 PostgreSQL 数组字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆