Appropriate class view to contain various forms of different objects

1

I want to do a view with three sections forms for three different objects, Priorities, States and Types to know. I have something like this .

I did it using modelformsets , in a list view, but I do not know what kind of view to use to be able to update each of the objects independently: I tried with UpdateView but I need a general object to return, ListView does not have a post method, and with the generic view we have the same case.

What solution should I implement in this case?

    
asked by SalahAdDin 09.10.2017 в 14:39
source

1 answer

0

There's something I do not understand about your code, and it's a curiosity, maybe this is not the error, but I do not know where the variable tag_formset comes from. In your views I do not see it defined, and since it is not defined, and call an attribute that would be management_form because simply the django template engine omits it, and does not throw an error.

Actually I'm not sure what django-oscar is for, I see that it's a plugin like online sales, but I'm not sure if it modifies the javascript, I'm not sure it could be affecting either, you just have to make sure that the data of management_form are being sent appropriately.

For that I tell you to verify the request, it is very simple, you can do it from the side of the browser, or from the side of the console, from the side of the browser, if you are in chrome for example, after clicking on the submit button, you can see in the developer tools, the section of Network and choose the request that matches the current url, then from there you go to the HEADERS tab, and down to the section that says FORM DATA .

The other way is from the server, you can go to your view in your method of forms_invalid and make a print of the errors of the form. You can do it by form, when you pass them, or the same formset in the following way formset.non_form_errors() Or simply make a print of what comes in the request before the form validates it, in this way print(request.POST)

What you must validate, is that in the request, you are sending these parameters:

'form-TOTAL_FORMS': '2',
'form-INITIAL_FORMS': '0',
'form-MIN_NUM_FORMS': '',
'form-MAX_NUM_FORMS': '',

If that information does not appear in the request, you should see what happens in your html, why these fields are not sent, then validate with javascript that the fields are present within the form, these fields are type="hidden" , as well that you can only see if you inspect the page.

Make sure that this information is updated as you dynamically add forms in the javascript, so that if you send 1 form the parameter form-TOTA_FORMS must be equal to 1, if you send 2, then equal to 2 and so on, because if not, the validation will fail, for the other parameters, you can see the django documentation about what should go in those fields.

Any questions comment.

    
answered by 01.11.2017 в 15:03