Django - Specifying default attr for Custom widget
        Posted  
        
            by 
                Pierre de LESPINAY
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Pierre de LESPINAY
        
        
        
        Published on 2012-03-28T10:43:28Z
        Indexed on 
            2012/03/28
            11:29 UTC
        
        
        Read the original article
        Hit count: 494
        
I have created this widget
class DateTimeWidget(forms.TextInput):
  attr = {'class': 'datetimepicker'}
  class Media:
    js = ('js/jquery-ui-timepicker-addon.js',)
Then I use it on my form
class SessionForm(forms.ModelForm):
  class Meta:
    model = Session
  def __init__(self, *args, **kwargs):
    super(SessionForm, self).__init__(*args, **kwargs)
    self.fields['start_time'].widget = DateTimeWidget()
    self.fields['end_time'].widget = DateTimeWidget()
No css class is applied to my fields (I'm expecting datetimepicker applied to both start_time & end_time).
I imagine I have put attr at a wrong location. Where am I supposed to specify it ?
© Stack Overflow or respective owner