Skip to main content

A Django app providing database and form fields for matrices (arrays of arrays).

Project description

A Django app providing database and form fields for matrices (arrays of arrays).

Examples

Database Field

from django.db import models
from matrix_field import MatrixField

class MyModel(models.Model):
    matrix1 = MatrixField(datatype='float', dimensions=(3, 2))
    matrix2 = MatrixField(datatype='str', dimensions=(2,))

my_inst = MyModel(
    matrix1=[[5.1, -1.2], [4.2, 0.0], [3.14, 2.71]],
    matrix2=['a list', 'of strings'],
)
my_inst.full_clean()  # validates datatype, dimensions
my_inst.save()        # values stored in DB as json

m1 = my_inst.matrix1  # values retrieved as matrices
repr(m1)              # '[[5.1, -1.2], [4.2, 0.0], [3.14, 2.71]]'

Form Field

import json
from django import forms
from matrix_field import MatrixFormField

class MyForm(forms.Form):
    matrix = MatrixFormField(datatype='int', dimensions=(2, 1))

my_form = MyForm({
    'matrix': json.dumps([[2], [1]]),  # assignment of json representation
})
my_form.full_clean()                   # validates datatype, dimensions

m = my_form.cleaned_data['matrix']  # values retrieved as matrices
repr(m)                             # '[[2], [1]]'

Found a Bug?

To file a bug or submit a patch, please head over to django-matrix-field on github.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_matrix_field-0.3.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

django_matrix_field-0.3-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file django_matrix_field-0.3.tar.gz.

File metadata

  • Download URL: django_matrix_field-0.3.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for django_matrix_field-0.3.tar.gz
Algorithm Hash digest
SHA256 c1757a2592399053286d2ea18f2bc204a2c011efd445b1d14e9a20b690e42c47
MD5 91bac78f94bd37c538ce9648b87454b1
BLAKE2b-256 5aa49a74e9227cf7d6645defbd0f1455f2c6823010edb5bfca0dd900473f9c07

See more details on using hashes here.

File details

Details for the file django_matrix_field-0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_matrix_field-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a5a32d9c797991ef7bd6d551fa9e7769573e8db59ac74244702460576f3412fc
MD5 5cd5a037cf1700ce7e21db06d0cbb19a
BLAKE2b-256 3ecfe6102789802631071cd0b268ab2745c90513d3997e661ea447f145c46538

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page