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

  • Home
  • SEARCH
  • 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 100117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:31:05+00:00 2026-05-11T00:31:05+00:00

Is it possible to have a variable number of fields using django forms? The

  • 0

Is it possible to have a variable number of fields using django forms?

The specific application is this:

A user can upload as many pictures as they want on the image upload form. Once the pictures are uploaded they are taken to a page where they can give the pictures a name and description. The number of pictures will depend on how many the user has chosen to upload.

So how do I get django to generate a form using a variable number of input fields (which could be passed as an argument if necessary)?

edit: a few things have changed since the article mentioned in jeff bauer’s answer was written.

Namely this line of code which doesn’t seem to work:

# BAD CODE DO NOT USE!!! return type('ContactForm', [forms.BaseForm], { 'base_fields': fields }) 

So here is what I came up with…

The Answer I used:

 from tagging.forms import TagField from django import forms  def make_tagPhotos_form(photoIdList):     'Expects a LIST of photo objects (ie. photo_sharing.models.photo)'      fields = {}      for id in photoIdList:         id = str(id)          fields[id+'_name'] = forms.CharField()         fields[id+'_tags'] = TagField()         fields[id+'_description'] = forms.CharField(widget=forms.Textarea)      return type('tagPhotos', (forms.BaseForm,), { 'base_fields': fields })  

note tagging is not part of django, but it is free and very useful. check it out: django-tagging

  • 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. 2026-05-11T00:31:06+00:00Added an answer on May 11, 2026 at 12:31 am

    Yes, it’s possible to create forms dynamically in Django. You can even mix and match dynamic fields with normal fields.

    class EligibilityForm(forms.Form):     def __init__(self, *args, **kwargs):         super(EligibilityForm, self).__init__(*args, **kwargs)         # dynamic fields here ...         self.fields['plan_id'] = CharField()     # normal fields here ...     date_requested = DateField() 

    For a better elaboration of this technique, see James Bennett’s article: So you want a dynamic form?

    http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 114k
  • Answers 114k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Keep in mind the session variable is backed by a… May 11, 2026 at 10:20 pm
  • Editorial Team
    Editorial Team added an answer Enclose the modification in: form.SuspendLayout(); and form.ResumeLayout(false); // read the… May 11, 2026 at 10:20 pm
  • Editorial Team
    Editorial Team added an answer this code worked for me DTP_deltek.CustomFormat = "MMM-dd-yyyy"; DTP_deltek.Format =… May 11, 2026 at 10:19 pm

Related Questions

So, I'm trying to stub a database connector in order to write tests for
I've just started working with ASP.NET MVC now that it's in beta. In my
I'm currently working on a small project with OCaml; a simple mathematical expression simplifier.
The stackpanel is not co-operating. We have a fixed width, and a variable number

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.