I have run into an interesting problem with newforms.  I am trying to
create an arbitrary number of fields on a form based on model data.
This works fine.

class SonglistForm(forms.Form):
        def __init__(self, *args, **kwargs):
                super(SonglistForm, self).__init__(*args, **kwargs)
                for song in Song.objects.all()[:100]:
                        self.fields['song_%s' % song.id] = 
forms.BooleanField(label='%s
(%s)' % (song.title, " & ".join([str(artist) for artist in
song.artists.all()])))

The problem occurs in the template.  I am trying to differentiate
these fields from the other normal fields on the form for presentation
purposes.  I have tried assigning a custom property to each of the
dynamic fields.

field = forms.BooleanField(label='%s (%s)' % (song.title, " &
".join([str(artist) for artist in song.artists.all()])))
field.is_song = True
self.fields['song_%s' % song.id] = field

However, this custom property is not accessible in the template.  How
can I differentiate these dynamic fields from the others in the
template (with limited access to Python code)?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to