5

I have a simple model

class Texts(models.Model):
    instructions_top_char
    instructions_top_char = ArrayField(models.CharField(max_length=maxLengthText), default=list, blank=True)

The problem with this model is that when Django creates the widget for the ArrayField it creates one CharField thing in which i have to input all of the texts.

Here is the output :

enter image description here

In order to properly create the array of texts I have to input the texts with ',' and no spaces like text1,text2,text3 ... which is very limiting and ugly.

Is there a way to make it so that I can have a '+' button so that the texts input can be split into multiple InputTexts ?

Something like

                       _________________________________
instructions top char: | text1                         | +
                       |-------------------------------|  

and when the + is pressed it becomes

                       _________________________________
instructions top char: |    text1                      |
                       |-------------------------------|  
                       |    text2                      | +
                       |-------------------------------|

and the 2 texts get saved correctly.

Thank you

mp3por
  • 1,796
  • 3
  • 23
  • 35

1 Answers1

0

You can create your own widget for ArrayField. Check out Django admin custom ArrayField widget

There also exists package django-better-admin-arrayfield https://pypi.org/project/django-better-admin-arrayfield/

quick
  • 1,104
  • 10
  • 19