0

In my django app i have models with CharField or Textfield fields; sometime i need to save in this field strings with more than one single space within word, like for example "hello world" but after save() process in my db i find thad the 3 spaces become 1.

i try:

from django.utils import safestring

but i don't know how to apply at the whole models fields

How can i maintain the exact string i write in my textbox with the exact number of spaces i need?

So many thanks in avance

Manuel Santi
  • 1,106
  • 17
  • 46

1 Answers1

0

Set strip to false in the init of your ModelForm:

  self.fields['myfield'].strip = False

If you aren't using a ModelForm you can create a custom Text Field, like said here:

https://stackoverflow.com/a/40709539/5434276

Mark Barrett
  • 366
  • 2
  • 16