0

I've read the documentation on models in Django and I don't see a clear way to implement what I'm hoping to do. I'd like to make a model where one of the fields is a 2 dimensional array. Something like this:

class DesignMatrix(models.Model):
    Matrix_name = models.CharField(max_length=50)
    Matrix_Description = models.CharField(max_length=50)
    ...
    Matrix = a 2-dimensional array of float values

Guidance is greatly appreciated.

cryptic_star
  • 1,863
  • 3
  • 26
  • 47
Jaime
  • 61
  • 1
  • 9

1 Answers1

0

This can be done if you are using PostgreSQL. Django recently added support for ArrayField.

https://docs.djangoproject.com/en/1.8/ref/contrib/postgres/fields/#arrayfield http://www.postgresql.org/docs/9.1/static/arrays.html

If that is not an option, consider serializing your 2D array to a text or binary field.

https://docs.python.org/2/library/pickle.html

mindcruzer
  • 834
  • 5
  • 9
  • I think I'll be going down the PostgreSQL route. I was hoping to not have to switch DB's, but in the end this is what needs to be done. Thanks for the help. – Jaime Sep 20 '15 at 17:10
  • since you're using Django's ORM it shouldn't be too painful of a transition – mindcruzer Sep 20 '15 at 17:14
  • Actually I'm having some issues with the transition to postgress. I'm posting it as a separate questions however. – Jaime Sep 22 '15 at 02:39