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: <lambda>() 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.