Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django form. How hide colon from initial_text?

I'm trying do this:


class NoClearableFileInput(ClearableFileInput):
    initial_text = ''
    input_text = ''

class ImageUploadForm(forms.ModelForm):
    title = forms.CharField(label="TITLE",  required=False,widget=forms.TextInput(attrs={'placeholder': 'name'}),  label_suffix="")
    image = forms.ImageField(label='NEW FILE',widget=NoClearableFileInput,  label_suffix="")

    class Meta:
        model = Image
        fields = ('title','image')

There in class NoClearableFileInput cleaned value initial_text. In fields 'title' and 'image' use label_suffix, but from initial_text symbol ":" remained.

result

How get rid of the colons?

like image 378
Richard B. Avatar asked Sep 20 '16 20:09

Richard B.


1 Answers

This just worked for me with Django 2.2:

class ImageUploadForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.label_suffix = ""  # Removes : as label suffix

    # ...the rest of the form code...
like image 82
Mark Chackerian Avatar answered Sep 27 '22 23:09

Mark Chackerian