The solutins I saw until now somehow contain injecting the attribute in the __init__ method:
class MyAuthenticationForm(AuthenticationForm):
def __init__(self, *args, **kwargs):
...
self.fields['username'].widget.attrs['placeholder'] = 'username'
...
Since this is done every instantiation, I feel like this is a bit redundant. In fact, these operations are negligible and should not affect performance at all. This solution does seem to work as well:
class MyAuthenticationForm(AuthenticationForm):
pass
MyAuthenticationForm.base_fields['username'].widget.attrs['placeholder'] = 'username'
...
It seems a bit dirty to change the class outside the class definition, but at least it is only called once and manipulates the class instead of the objects which seems on the other hand much more reasonable.
What do you think? Is there a hook that is only called once the class is created? Are there benefits or drawbacks?
Greets