11

How to define ArrayField in django form

I have some function params for which I want to add validation so I created a form and one of the function parameter is list. How can I define that in forms

from django.contrib.postgres.fields import ArrayField

class SampleParams(forms.Form):
    num = forms.IntegerField()
    li = ArrayField(forms.CharField(max_length=100, required=False))

but I think ArrayField is related when I want to store data in database but my case is just to validate the params but not store data

2
  • What do you actually want to have in the form? What data do you want to validate and how should it be entered? Commented May 20, 2019 at 10:01
  • just want to have some Integer, String and array data, so i could define IntegerField, CharFied but not ArrayField in form (form is not related to any model) Commented May 20, 2019 at 10:11

1 Answer 1

19
from django.contrib.postgres.forms import SimpleArrayField
li = SimpleArrayField(forms.CharField(max_length=100))
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.