def add_placeholders(cls): """Add placeholders by widget type to a Form type.""" for field in cls.base_fields.values(): widget_type = type(field.widget) if widget_type == forms.TextInput: field.widget = forms.TextInput(attrs={'placeholder': field.label}) elif widget_type == forms.Textarea: field.widget = forms.Textarea(attrs={'placeholder': field.label}) return cls def add_placeholders_to_any_field(cls): """Add placeholders to any field to a Form type.""" for field in cls.base_fields.values(): field.widget.attrs["placeholder"] = field.label return cls