[Answer]-Django โ€“ while creating object from request.POST from modelformset_factory takes lot of time and sometimes crashes server

1๐Ÿ‘

โœ…

Well you are looping through potentially very long list of objects, calling them up from base again and then saving them (twice if i read it correctly) โ€“ that is alot of queries.

What you could do is:

1) Pass the value of author to formset, add author as field to form, set it in form init method

2) add verified_to_usr to form as hidden field. Set it to True in form init method

3) just save the formset.

In response to comment โ€“ https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#model-formsets. THe place where it says that if you do not pass queryset as parameter to formset, then it will use relevantmodel.objects.all() as default queryset. (link). I think you missed that before. I said you are looping through very long list there โ€“ i thought it was intentional, that you had not passed another queryset as value to formset. Thats where the problems come from was my guess.

alan

๐Ÿ‘คOdif Yltsaeb

Leave a comment