Use array in postgresql with django

Posted 27.01.2013

I wanted to use arrays in postgresql for tags on this blog. I installed the packages djorm-ext-pgarray and djorm-ext-expressions. The model for the blogposts is displayed below.

from django.db import models
from djorm_expressions.models import ExpressionManager
from djorm_pgarray.fields import ArrayField

class Post (models.Model):
    title = models.CharField(max_length=80)
    slug = models.SlugField()
    pub_date = models.DateField()
    content = models.TextField()
    tags = ArrayField(dbtype="varchar(60)")
    objects = ExpressionManager()

The tags field is using djorm_pgarray.fields.ArrayField and the ExpressionManagaer is needed if one would need to make a query using the ArrayField.