title: Dynamic django forms - Variable fields
body: <p>I have some models; Vocabularies (tags lists), Labels (tags) and different articles types.</p>
  
  <p>These article types have some vocabs enabled, and some not, for instance: Image can tagged with terms from A, B and a news article with terms from A or C.</p>
  
  <p>This however only exists at the database level.</p>
  
  <p>What i'm trying to do is to output fields depending on if a vocab is enabled for a content type or not, like this:</p>
  
  <ul>
  <li><p>Determine if this content type is connected to a vocabulary.</p></li>
  <li><p>Load the vocabularies</p></li>
  <li><p>output a CharField or Select for each vocabulary.</p></li>
  </ul>
  
  <p>All my efforts for the last step have failed however, so I'm hoping someone can point me in the right direction.</p>
  
  <hr>
  
  <p>My apologies for not being very clear about the code I am using, so here it is:</p>
  
  <p>Vocabulary
  - Tags</p>
  
  <p>NewsArticle can use tags from vocab 1, 3
  Blog can use tags from vocab 1,2</p>
  
  <p>This code get's the vocabularies which are enabled for the content type:</p>
  
  <pre><code>    def get_vocabularies(self, type = None):
      vocabularies = {}
      object = namedtuple("Vocabulary", "vid name desc help relations hierarchy multiple req tags weight")
      if (type != None):
          vocabs = VocabularyTypes.objects.filter(type=type)
          for vocab in vocabs:
              v = Vocabulary.objects.get(pk=vocab.vid)
              vocabularies[v.vid] = object(vid = v.vid, 
                                           name = v.name, 
                                           desc = v.desc,
                                           help = v.help,
                                           relations = v.relations,
                                           hierarchy = v.hierarchy,
                                           multiple = v.multiple,
                                           req = v.req,
                                           tags = v.tags,
                                           weight = v.weight
                                         )
      else:
          vocabs = Vocabulary.objects.all()
          for v in vocabs:
              vocab = Vocabulary.objects.get(pk=v.vid)
              vocabularies[v.vid] = object(vid = vocab.vid, 
                                           name = vocab.name, 
                                           desc = vocab.desc,
                                           help = vocab.help,
                                           relations = vocab.relations,
                                           hierarchy = vocab.hierarchy,
                                           multiple = vocab.multiple,
                                           req = vocab.req,
                                           tags = vocab.tags,
                                           weight = vocab.weight
                                         )
  
      return vocabularies
  </code></pre>
  
  <p>So code I have tried so far is this:</p>
  
  <pre><code>    def free_tags(self, type):
      vocabs = Label.objects.get_vocabularies(type)
  
      for vid in vocabs.keys():
          output = forms.CharField(label=vocabs[vid].name,
                                   required = vocabs[vid].req,
                                   widget = forms.TextInput(attrs={'size' : 64})
                                   )
          return output
  </code></pre>
  
  <p>However, when using it in a view it prints out the internal python identifier (object intance at ... etc).</p>
  
  <p>Another problem however, it that these field have no name i.e. they are all called 'output'.</p>
  
  <p>So what I need to find out is how output a number of fields, when the number of fields is unknown.</p>