rewrite the __init__., redefining the form element in this place. The error must to dissapear.
class FormMyForm(ModelForm): def __init__(self, *args, **kwargs): super(FormMyForm, self).__init__(*args, **kwargs) self.fields['aaaa'] = forms.CharField(widget=forms.TextInput(attrs={.....})) class Meta: model = Model fields = ['aaaa'] On 1 sep, 12:01, Jason <goodri...@gmail.com> wrote: > Thanks! I'll give that a try. > > On Aug 13, 8:55 am, Matthew R <mrich...@gmail.com> wrote: > > > I got hit by this same bug and here's the workaround I used, for > > future reference. Basically you need to specify a formfield_callback > > kwarg to modelformset_factory that just passes along any kwargs it > > receives (namely, in this case, the 'widget' argument) to > > Field.formfield(): > > > def create_formfield(f, **kwargs): > > return f.formfield(**kwargs) > > > ArticleFormSet = modelformset_factory(Article, > > form = ArticleForm, > > formfield_callback=create_formfield, > > extra=0) > > > On Jul 29, 11:33 am, Jason <goodri...@gmail.com> wrote: > > > > Can anyone confirm that passing in a form withMeta.widgets set to > > > modelformset_factory() does in fact work? > > > > I've tried stripping my code down to the basics and still get the same > > > exception. Debugging Django code doesn't help me because it fails > > > during a lamda function that I don't quite understand. > > > > If anyone else has this problem I'll go ahead and submit a bug report. > > > > On Jul 28, 12:50 pm, Jason <goodri...@gmail.com> wrote: > > > > > Traceback: > > > > File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in > > > > get_response > > > > 100. response = callback(request, > > > > *callback_args, **callback_kwargs) > > > > File "C:\Documents and Settings\goodrich\PycharmProjects\CCC\Aggregator > > > > \newsmail\views.py" in manage_articles > > > > 174. form = ArticleForm) > > > > File "C:\Python25\lib\site-packages\django\forms\models.py" in > > > > modelformset_factory > > > > 669. > > > > formfield_callback=formfield_callback) > > > > File "C:\Python25\lib\site-packages\django\forms\models.py" in > > > > modelform_factory > > > > 407. return ModelFormMetaclass(class_name, (form,), > > > > form_class_attrs) > > > > File "C:\Python25\lib\site-packages\django\forms\models.py" in __new__ > > > > 220. opts.exclude, > > > > opts.widgets, formfield_callback) > > > > File "C:\Python25\lib\site-packages\django\forms\models.py" in > > > > fields_for_model > > > > 178. formfield = formfield_callback(f, **kwargs) > > > > > Exception Type: TypeError at /newsmail/manage/ > > > > Exception Value: <lambda>() got an unexpected keyword argument > > > > 'widget' > > > > > On Jul 28, 12:00 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > > > > > > On Jul 28, 7:08 pm, Jason <goodri...@gmail.com> wrote: > > > > > > > For example: > > > > > > > class ArticleForm(ModelForm): > > > > > > classMeta: > > > > > > model = Article > > > > > > widgets = { > > > > > > 'pub_date': SplitSelectDateTimeWidget(), > > > > > > 'expire_date': CalendarWidget(attrs={'class':'date- > > > > > > pick'}) > > > > > > } > > > > > > > And in a view function: > > > > > > ... > > > > > > ArticleFormSet = modelformset_factory(Article, > > > > > > form = ArticleForm, > > > > > > extra=0) > > > > > > ... > > > > > > > Removing 'widgets' from theMetain ArticleForm fixes the error. > > > > > > > The new widgets convention here is really handy. I don't want to > > > > > > lose > > > > > > it! > > > > > > > Any tips? > > > > > > How does it fail? What error do you get? If there's a traceback, > > > > > please post it here. > > > > > -- > > > > > DR. -- 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.