Note that there are some explanatory texts on larger screens.

plurals
  1. POis_valid always False (Django)
    primarykey
    data
    text
    <p>I have the following form with dynamic fields:</p> <p><em>1</em>) In <strong>models.py</strong> I want to pass in a value to the form to query</p> <pre><code>class InsertValuesForm(forms.Form): def __init__(self, idfield, *args, **kwargs): super(InsertValuesForm, self).__init__(*args, **kwargs) for f in Parameter.objects.filter(id=idfield): if Part.objects.get(parameter=f.parameter_name).isfunction: self.fields.update({ f.parameter_name) : forms.CharField(widget=forms.TextInput() )}) </code></pre> <p><em>1)</em> In <strong>views.py</strong></p> <pre><code>def something(request) #...... idfield = request.GET.get('feid','0') form = InsertValuesForm(request.POST,idfield) if request.method == 'POST': if form.is_valid(): #some code else: form = InsertValuesForm(idfield) return render_to_response('fuzz/configuration.html', { 'form': form, },context_instance=RequestContext(request)) </code></pre> <p>In number 1 situation, I was able to display the dynamic fields in the for loop. However, the form threw me this error after filling up all of the fields and submitting(POST): </p> <p>int() argument must be a string or a number, not 'QueryDict'. I was thinking it is the request.POST that is causing the error. after doing some research on this problem, there were similar solutions like this:</p> <p><a href="http://groups.google.com/group/django-users/browse_thread/thread/ddefd76324ffe6cd" rel="nofollow">http://groups.google.com/group/django-users/browse_thread/thread/ddefd76324ffe6cd</a> <a href="http://groups.google.com/group/django-users/browse_thread/thread/495a917396b20b37/c430d71a31204e5d#c430d71a31204e5d" rel="nofollow">http://groups.google.com/group/django-users/browse_thread/thread/495a917396b20b37/c430d71a31204e5d#c430d71a31204e5d</a></p> <p><em>2)</em> In <strong>models.py</strong> </p> <pre><code>class InsertValuesForm(forms.Form): def __init__(self, *args, **kwargs): idfield = kwargs.pop('idfield', False) super(InsertValuesForm, self).__init__(*args, **kwargs) for f in Parameter.objects.filter(id=idfield): if Part.objects.get(parameter=f.parameter_name).isfunction: self.fields.update({ f.parameter_name) : forms.CharField(widget=forms.TextInput() )}) </code></pre> <p>and </p> <p>the following snippet of views.py(same as number 1)</p> <pre><code>def something(request) #...... idfield = request.GET.get('feid','0') form = InsertValuesForm(request.POST,idfield) if request.method == 'POST': if form.is_valid(): #some code else: form = InsertValuesForm(idfield) return render_to_response('fuzz/configuration.html', { 'form': form, },context_instance=RequestContext(request)) </code></pre> <p>Now the above code doesn't even display the dynamic textboxes and is just displayed as blank page. Appreciate if anybody can shed some light on </p> <p>how to display these dynamic textboxes and at the same time, getting the values of these textboxes via request.POST and also making the form validate. Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload