Kelvin
Kelvin

Reputation: 42

How to retrieve all values inside Django Postgres Array Field?

I used Django ArrayField with Postgres Database, I read the documentation however I cannot find a method to retreive all values saved inside the array field.

After retrieved the record from database, I want to convert ArrayField type into python list type.

This is their documentation

Upvotes: 2

Views: 2160

Answers (1)

Lucas Resende
Lucas Resende

Reputation: 612

Simply instanciate the target object and retrieve the information from the attribute name

My model: I think you want something this:

from django.contrib.postgres.fields import ArrayField

class ModelTest(models.Model):
    board = ArrayField(
        ArrayField(
            models.IntegerField(),
            size=2,
        ),
        size=2,
    )

My test is, first create one object and get the object, next i retrieve board attribute:

enter image description here

The return is a list of list in python

Upvotes: 2

Related Questions