0

I have problem with ArrayField in django admin. When I trying save object with None values, even it wasn't changed, I get error: Item 5 in the array did not validate: Enter a whole number. Model looks like this:

class MyModel(models.Model):
    rank = ArrayField(
        models.PositiveIntegerField(null=True)
    )

and field data 4,4,4,4,4,None,4,4 How I can fix this problem?

1 Answer 1

4

Django form fields will only set null values if it matches one of EMPTY_VALUES from validators

EMPTY_VALUES = (None, '', [], (), {})

SimpleArrayField first splits the incoming data resulting in ['4', '4', '4', '4', '4', 'None', '4', '4'], the string 'None' does not match the literal None so does not get converted to a null value

You need to pass an empty string: 4,4,4,4,4,,4,4 as your field data

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.