Re: add attributes to a field without widgets
Opps, I forgot to mention that I work with "Django 1.2.1". Apparently is a Django bug. Other persons has the same question "http://groups.google.com/group/ django-users/browse_thread/thread/c4899b0806e67ee7/d938f33a5f100af8? show_docid=d938f33a5f100af8=1" I will try to implement the solution you mention. thanks for answer. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: add attributes to a field without widgets
Hi refreegrata, On Aug 11, 2010, at 3:31 PM, refreegrata wrote: Hello list. I'm a newbie in django and now i am working with "modelformset_factory". I have something like this -- class MyForm(forms.ModelForm): myField = forms.BooleanField() class Meta: model = Format fields = ['name'] widgets = {'name' : forms.TextInput(attrs={ something }),} FormsetMyForm= forms.models.modelformset_factory(Format, max_num=0, form=MyForm) -- With that code, django throw an error "Exception Value: () got an unexpected keyword argument 'widget'", but i solve the problem deleting the "widget" declaration. Now my question is: Can i add attributes in other side with Django ? a Template for example, something like "{% field class="myclass" %}". Your Django version is probably too old for Meta-widgets. What I do in this case is setting the widget attrs on form object creation: def __init__(self, *args, **kwargs): super(MyForm, self).__init__(*args, **kwargs) # If you want an other widget: # self.fields['name'].widget = forms.TextInput(attrs={something...}) self.fields['name'].widget.attrs['something'] = ... Cheers, Roald -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
add attributes to a field without widgets
Hello list. I'm a newbie in django and now i am working with "modelformset_factory". I have something like this -- class MyForm(forms.ModelForm): myField = forms.BooleanField() class Meta: model = Format fields = ['name'] widgets = {'name' : forms.TextInput(attrs={ something }),} FormsetMyForm= forms.models.modelformset_factory(Format, max_num=0, form=MyForm) -- With that code, django throw an error "Exception Value: () got an unexpected keyword argument 'widget'", but i solve the problem deleting the "widget" declaration. Now my question is: Can i add attributes in other side with Django ? a Template for example, something like "{% field class="myclass" %}". thanks for read. P.D.: sorry for my poor english -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.