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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1757a2592399053286d2ea18f2bc204a2c011efd445b1d14e9a20b690e42c47
|
|
| MD5 |
91bac78f94bd37c538ce9648b87454b1
|
|
| BLAKE2b-256 |
5aa49a74e9227cf7d6645defbd0f1455f2c6823010edb5bfca0dd900473f9c07
|
File details
Details for the file django_matrix_field-0.3-py3-none-any.whl.
File metadata
- Download URL: django_matrix_field-0.3-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5a32d9c797991ef7bd6d551fa9e7769573e8db59ac74244702460576f3412fc
|
|
| MD5 |
5cd5a037cf1700ce7e21db06d0cbb19a
|
|
| BLAKE2b-256 |
3ecfe6102789802631071cd0b268ab2745c90513d3997e661ea447f145c46538
|