5
votes

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?

2

2 Answers

12
votes

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...
1
votes

You have to override the label_suffix on initialization. Try making the following changes:

class ImageUploadForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('label_suffix', '')
        super(ImageUploadForm, self).__init__(*args, **kwargs)

    # ... (the rest of your code) ...