On Dec 18, 7:18 pm, Cortland Klein <cortl...@apple.com> wrote:
> I'm using inlineformset_factory in one of my views, which is working  
> great, except now I'd like to change the widget for one of the fields  
> (in case anyone's curious, an AdminFileWidget). For clarification this  
> is my own view and has nothing to do with contrib/admin.
>
> I see that inlineformset_factory has something for fields, but I'm not  
> sure what to pass to it to override a field's widget:
>
> # django/forms/models.py
>
> > def inlineformset_factory(parent_model, model, form=ModelForm,
> >                           formset=BaseInlineFormSet, fk_name=None,
> >                           fields=None, exclude=None,
> >                           extra=3, can_order=False, can_delete=True,  
> > max_num=0,
> >                           formfield_callback=lambda f: f.formfield()):


Panta has given you one possibility, using the formfield_callback
parameter. An alternative is to define your own ModelForm subclass and
pass that in the form parameter.

class FileForm(forms.ModelForm):
    file = forms.FileField(widget=AdminFileWidget)
    class Meta:
        model = File

FileFormSet = inlineformset_factory(Version, File, extra=1,
form=VersionForm)

--
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-users@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
-~----------~----~----~----~------~----~------~--~---

Reply via email to