I was using new forms for one of my forms, and i wanted to save a
relation.
i came upon an interesting problem along the way. is there a limit in
python on the number of chained function calls or something?

This did not work:

class q_to_q_form(forms.Form):
    def __init__(self, columns, question, *args, **kwargs):
        super(q_to_q_form, self).__init__(*args, **kwargs)
        self.question = question
        self.fields['link'] = q2qModelChoiceField(required = False,
queryset = columns, label=question.asked_question)
    def save(self):
        self.question.options().q_column = self.cleaned_data['link']
        self.question.options().q_column.save()


This worked:

class q_to_q_form(forms.Form):
    def __init__(self, columns, question, *args, **kwargs):
        super(q_to_q_form, self).__init__(*args, **kwargs)
        self.options = question.options()  ####################This
line############
        self.fields['link'] = q2qModelChoiceField(required = False,
queryset = columns, label=question.asked_question)
    def save(self):
        self.options.q_column = self.cleaned_data['link'] ###########
and this line #########
        self.options.save()


all i did was move a function over....


other info that might help

class q2qModelChoiceField(forms.ModelChoiceField):
    def label_from_instance(self, obj):
        return obj.value


inside my Question model class is method

    def options(self):
        if ##criteria ##
            ## other code here ##
        elif ## criteria ##
            options, created =
some_other_object.objects.get_or_create(question=self)
            return options


This confused me for a long time, and baffles me that just moving that
one thing over made it work.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to