Skip to content
This repository was archived by the owner on Nov 14, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ndarraydjango/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ def from_db_value(self, value, expression, connection):
return parse_numpy_array(value)

def validate(self, value, model_instance):

if (
( value is None and self.blank ) or
( value is None and self.null )
):
return

if self.shape is not None and value.shape != self.shape:
raise exceptions.ValidationError("Bad shape", code="shape")

Expand All @@ -103,6 +110,11 @@ def to_python(self, value):
return value

if isinstance(value, str):
if (
( value=='' and self.blank ) or
( value=='' and self.null )
):
return None
try:
value = np.array(json.loads(value), dtype=self.dtype)
except json.decoder.JSONDecodeError:
Expand Down
2 changes: 2 additions & 0 deletions ndarraydjango/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def prepare_value(self, value):

def to_python(self, value):
value = super().to_python(value)
if (value==self.empty_value) and (not self.required):
return value
try:
value = json.loads(value)
except json.decoder.JSONDecodeError:
Expand Down