Hi - I've been attempting to put together a website to use for keeping track of information for a wedding, and I'm wanting to use multiple inline lists of invitees within each group that has been sent an invite. Basically I want something like the admin interface where one can do tabular inline editing. I'm also new to both python and django.
I've tried following along with this: http://www.hoboes.com/Mimsy/?ART=607 I've also read what is on the list here regarding using MultiValueFields, and I can get things working with a fixed number of elements in a MultiValueField, but things are breaking down for me with greater numbers. I'm getting the following error: 'NoneType' object is unsubscriptable This, I presume has to do with the way that I'm doing/not doing compress/decompress on the data for the Fields and Widgets, but I'm lost as to what I need to do within these functions to give valid output. Here's a portion of the code I'm using. Any suggestions as to why when I do the following: a = weddingsite.register.views.GroupForm() print a I get: File "<console>", line 1, in <module> File "/Library/Python/2.5/site-packages/django/utils/encoding.py", line 25, in __str__ return self.__unicode__().encode('utf-8') File "/Library/Python/2.5/site-packages/django/newforms/forms.py", line 86, in __unicode__ return self.as_table() File "/Library/Python/2.5/site-packages/django/newforms/forms.py", line 169, in as_table return self._html_output(u'<tr><th>%(label)s</th><td>%(errors)s% (field)s%(help_text)s</td></tr>', u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', u'<br />%s', False) File "/Library/Python/2.5/site-packages/django/newforms/forms.py", line 151, in _html_output output.append(normal_row % {'errors': force_unicode(bf_errors), 'label': force_unicode(label), 'field': unicode(bf), 'help_text': help_text}) File "/Library/Python/2.5/site-packages/django/newforms/forms.py", line 265, in __unicode__ return self.as_widget() File "/Library/Python/2.5/site-packages/django/newforms/forms.py", line 293, in as_widget return widget.render(self.html_name, data, attrs=attrs) File "/Library/Python/2.5/site-packages/django/newforms/widgets.py", line 423, in render widget_value = value[i] TypeError: 'NoneType' object is unsubscriptable Here's the relevant code: class InviteeNameWidgets(forms.MultiWidget): def __init__(self, attendee_count=1, attrs=None): widgets = (forms.TextInput(),)*attendee_count super(InviteeNameWidgets, self).__init__(widgets=widgets, attrs=attrs) def decompress(self, value): return value class EventAttendanceWidgets(forms.MultiWidget): def __init__(self, attendee_count=1, attrs=None): widgets = (forms.CheckboxInput(),)*attendee_count super(EventAttendanceWidgets, self).__init__(widgets=widgets, attrs=attrs) def decompress(self, value): return value class InviteeNameFields(forms.MultiValueField): widget = InviteeNameWidgets def __init__(self, required=True, attendee_count=1, **kwargs): fields = (forms.CharField(),)*attendee_count super(InviteeNameFields, self).__init__(**kwargs) def compress(self, data_list): return data_list class EventAttendanceFields(forms.MultiValueField): widget = EventAttendanceWidgets def __init__(self, required=True, attendee_count=1, **kwargs): fields = (forms.BooleanField(),)*attendee_count super(EventAttendanceFields, self).__init__(fields=fields,**kwargs) def compress(self, data_list): return data_list class GroupForm(forms.Form): email = forms.EmailField() invitee_name = InviteeNameFields(attendee_count=2) invitee_attend_wedding = EventAttendanceFields(attendee_count=2) invitee_attend_reception = EventAttendanceFields(attendee_count=2) # I know I need to initialize the other default values here, but right now i'm just trying to get invitee_name working without pulling from the database def initialize_invitees(self): for invitee_id in range(1,3): name_key = "invitee_name_" + str(invitee_id) self.data[name_key] = 'testing' def __init__(self, **kwargs): self.group_id = 1 super(GroupForm, self).__init__(**kwargs) self.initialize_invitees() --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---