Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5930727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:35:37+00:00 2026-05-22T14:35:37+00:00

I have the following form with dynamic fields: 1 ) In models.py I want

  • 0

I have the following form with dynamic fields:

1) In models.py I want to pass in a value to the form to query

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() )})

1) In views.py

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))

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):

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:

http://groups.google.com/group/django-users/browse_thread/thread/ddefd76324ffe6cd
http://groups.google.com/group/django-users/browse_thread/thread/495a917396b20b37/c430d71a31204e5d#c430d71a31204e5d

2) In models.py

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() )})

and

the following snippet of views.py(same as number 1)

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))

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

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:35:38+00:00Added an answer on May 22, 2026 at 2:35 pm

    You have changed the signature of the form’s __init__ so that the first positional parameter is idfield. Don’t do that, because now when you instantiate it with form = InsertValuesForm(request.POST,idfield), it’s taking the first parameter to be idfield, rather than request.POST.

    Instead, define the method like this:

     def __init__(self, *args, **kwargs):
          idfield = kwargs.pop('idfield', None)
          ...etc...
    

    and instantiate it with a keyword arg:

    form = InsertValuesForm(request.POST, idfield=idfield)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following form code: # forms.py class SomeForm(forms.Form): hello = forms.CharField(max_length=40) world
I have a dynamic form with the following fields <tr> <td><input name = qty[]
I have the following form for photo_album which uses the nested forms feature of
I'm looking at some Java classes that have the following form: public abstract class
I have the following rails form (which works) but I want to remove the
I have a form that has all the fields pulled dynamic from a database
I have a simple data table which contains dynamic form text fields. Each field
I have an HTML form with a dynamic number of checkbox fields, all of
I have the following form, which I have reduced as much as I can,
I have the following form <form name=myForm id=myForm method=post enctype=multipart/form-data action=script.php> and this jQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.