How to create an empty Django formset using modelformset_factory?

I am creating a formset, but it seems to populate it with all the existing data in the table for this object. I cannot figure out how to start with an empty form; the only way is to delete all the data from the table, but this is clearly not an option.

If necessary, I will send the code (but there are many, so knowing what's up-to-date is difficult).

+5
source share
3 answers

set queryset = Model.objects.none () to create the object.

+9
source

After Arihant's answer, I did something like this:

class TagCreateFormSet(BaseModelFormSet):
    def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
             queryset=None, **kwargs):
        queryset = Tag.objects.none()
        super(TagCreateFormSet, self).__init__(data, files, 
            auto_id, prefix, queryset, **kwargs)
+1
source

, . , , , , , inlineformset_factory.

0
source

All Articles