from django.db import model
import dbarray
class ProfilingTestRun(models.Model):
function = models.CharField(max_length=64)
runtimes = dbarray.FloatArrayField()
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()
from django.contrib.postgres.fields import ArrayField
from django.db import models
class GoGame(models.Model):
board = ArrayField(ArrayField(models.IntegerField(),size=19),size=19)
from django.contrib.postgres.fields import ArrayField
from django.db import models
class GoGame(models.Model):
board = ArrayField(ArrayField(models.IntegerField(),size=19),size=19)
发布评论
评论(6)
您可能想查看 github 上的 django-dbarray 。它添加了对 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:
其他不错的选择之一是 http://django-orm.readthedocs.org/ ---一个向许多本机 postgres 类型添加绑定的库。
django-orm
的主要缺点是截至目前它还没有对south
的有效支持。One of the other nice options is http://django-orm.readthedocs.org/ --- a library that adds bindings to many native postgres types.
Main drawback of
django-orm
is that as of today it has no working support forsouth
.djorm-ext-pgarray 还提供查询
http://www.niwi.be/2012/ 10/07/postgresql-array-fields-with-django/
djorm-ext-pgarray also offer queries
http://www.niwi.be/2012/10/07/postgresql-array-fields-with-django/
Django 即将对 PostgreSQL 特定模型字段提供本机支持(在 django.contrib.postgres.fields 模块中):
Native support for PostgreSQL specific model fields is coming soon to Django (in the django.contrib.postgres.fields module):
从 Django 1.8 开始,有一个 django.contrib.postgress 模块 添加了对 数组字段以及其他 PostgreSQL 数据类型。
例如你可以这样做:
Since Django 1.8 there is a django.contrib.postgress module that adds support to array fields among other PostgreSQL data types.
For example you can do something like this:
您必须子类化 model.Field 并编写输入和输出方法。
http://docs.djangoproject.com/ en/dev/howto/custom-model-fields/#custom-database-types
you have to subclass
model.Field
and write input and output methods.http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#custom-database-types