ManyToManyField Widget: saving object does not work
|Reported by:||sindrero||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In our application, we are unable to save a ManyToManyField, using the standard webform widgit. MultipleSelectChecbox also does not work. The scalar_properties, remain an empty list when objects are added through the webform. All other fields are properly saved.
When examining the request.POST object, I se that a numeric value is returned. However request.POST includes only ONE numeric value, when it SHOULD have returned several. The number returned, is always equal to the numbering of the last selected element in the list. (The last element in the list is named 1, the second last is named 2 an so on.) There seems to be no way of extracting all objects that are actually selected out from the returned number.
Example code (simplification of our aplication):
in models.py, we have somthing like:
... class Calculation(models.Model): ... scalar_properties = fields.ManyToManyField("ScalarProperty") ... class ScalarProperty(models.Model) ...
in views.py we have:
def edit(request, ...): instance = ... # The original object, before editing if request.POST.method == "GET": # Create form: .... elif request.POST.method == "POST": # Save object from form: calc = forms.CalculationForm(request.POST, instance=instance).save(commit=False) ... calc.save() # Redirect: ... ...