Create Placeholders

To add placeholders for the fields in your AddNewsForm, you can use the widgets attribute inside the Meta class. Each field can have its own widget with a attrs dictionary, where you define the placeholder text.

Before..
After

Here's how your updated code would look with placeholders:

class AddNewsForm(TranslatableModelForm):
    # content = forms.CharField(widget=CKEditorWidget())
    class Meta:
        model = PostNews
        fields = ['title', 'content', 'images', 'category', 'slug']

        widgets = {
            'title': forms.TextInput(attrs={'placeholder': 'Enter the news title'}),
            'images': forms.ClearableFileInput(attrs={'placeholder': 'Upload related images'}),
            'category': forms.Select(attrs={'placeholder': 'Choose a category'}),
            'slug': forms.TextInput(attrs={'placeholder': 'Enter a unique slug (optional)'}),
        }

Last updated