class formfield_widget_attrs(object): u''' Add HTML attributes to Form Fields created by ModelForm: Example: tag should have attribute size=60: class MyModel(models.Model): name=models.CharField() name.formfield=modelutils.formfield_widget_attrs(name.formfield, size='60') ''' def __init__(self, method, **kwargs): self.method=method self.kwargs=kwargs def __call__(self, *args, **kwargs): formfield_instance=self.method(*args, **kwargs) formfield_instance.widget.attrs.update(self.kwargs) return formfield_instance