[Django]-Django: Add field to model formset

12👍

You can add fields. Just define a form in the normal way, then tell modelformset_factory to use that as the basis for the formset:

MyPhotoForm(forms.ModelForm):
    delete_box = forms.BooleanField()

    class Meta:
        model = Photo
        exclude=('effect',
                 'caption',
                 'title_slug',
                 'crop_from',
                 'is_public',
                 'slug',
                 'tags'
                ))

PhotoFormSet = modelformset_factory(Photo, form=MyPhotoForm)

Leave a comment