My apologies for not being very clear about the code I am using, so here it is:
Vocabulary
- Tags
NewsArticle can use tags from vocab 1, 3
Blog can use tags from vocab 1,2
This code get's the vocabularies which are enabled for the content type:
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
So code I have tried so far is this:
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
However, when using it in a view it prints out the internal python identifier (object intance at ... etc).
Another problem however, it that these field have no name i.e. they are all called 'output'.
So what I need to find out is how output a number of fields, when the number of fields is unknown.