My apologizes if this question was somewhere before, but I could not find anything.
So, the question is really simple: is these any django native formfield that mimics the behavior of request.POST.getlist('something')?
In my UI, user creates a list of objects that he wants to save, and these objects are represented as a list of hidden inputs with the same name:
<input type="hidden" name="cc" value="1045">
<input type="hidden" name="cc" value="1055">
<input type="hidden" name="cc" value="1046">
request.POST.getlist does exactly what I need, but I don't want to work with the request directly, I want do to it through the form.
Thanks for the comment. Yes I found that ModelChoiceField is used to ManyToMany fields in models. On the form side, it is represented as MultipleChoiceField/TypedMultipleChoiceField.
So I decided to subclass this field and override validate methods.
class NotValidatedMultipleChoiceFiled(forms.TypedMultipleChoiceField):
"""Field that do not validate if the field values are in self.choices"""
def to_python(self, value):
"""Override checking method"""
return map(self.coerce, value)
def validate(self, value):
"""Nothing to do here"""
pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With