I have just recently started using forms. I was avoiding them because
I thought they were not very DRY, but discovered I need them for added
flexibility such as displaying field lengths for example.

Anyway, I have created a Form for a Survey object that I use. If I go
to my edit page for a Survey, everything works perfectly. If I go to
do a simple add new (like right out of the docs), I always receive an
error "NoneType' object is not callable". So I am assuming I am trying
to use something not in existence yet, but it seems bizarre to me (but
I am a form noob and hoping I am doing something stupid (at least 1
thing)). Here is my model

class Survey(models.Model):
        """Highest level class that defines the attriutes of a survey"""
        STATUS_CHOICES = (
                ('A', 'Active'),
                ('C', 'Complete'),
                ('D', 'Development'),
        )

        TYPE_CHOICES = (
                ('A', 'Public'),
                ('B', 'Private'),
        )

        STATUS_DBS = (
                ('A', 'MySQL'),
                ('B', 'MS SQL'),
        )

        STATUS_OS = (
                ('A', 'Linux'),
                ('B', 'OS X'),
                ('C', 'Unix'),
                ('D', 'Windows'),
        )

        STATUS_LANG = (
                ('A', 'English'),
        )

        STATUS_ENC = (
                ('A', 'Autodetect'),
                ('B', 'Utf8 (UTF-8 unicode)'),
                ('C', 'ISO Latin 1 (latin1)'),
        )


        name = models.CharField(max_length=50)
        client = models.ForeignKey(User)
        gen_source_path = models.CharField(max_length=100)
        gen_dest_path = models.CharField(max_length=100)
        url = models.CharField(max_length=100, blank=True)
        db_type = models.CharField(max_length=1, choices=STATUS_DBS)
        db_name = models.CharField(max_length=50)
        table_name = models.CharField(max_length=50)
        cookie_name = models.CharField(max_length=50)
        header_title1 = models.CharField(max_length=50)
        header_title2 = models.CharField(max_length=50)
        header_title3 = models.CharField(max_length=50)
        footer_title1 = models.CharField(max_length=50)
        footer_title2 = models.CharField(max_length=50)
        status = models.CharField(max_length=1, choices=STATUS_CHOICES)
        survey_type = models.CharField(max_length=1, choices=TYPE_CHOICES)
        operating_system = models.CharField(max_length=1, choices=STATUS_OS)
        language = models.CharField(max_length=1, choices=STATUS_LANG)
        encoding = models.CharField(max_length=1, choices=STATUS_ENC)

        def __unicode__(self):
                return self.name

        def client_name(self):
                return str(self.client.user)

        class Meta:
            ordering = ["name"]

and this is the form:

class SurveyForm(forms.ModelForm):

        """Highest level class that defines the attriutes of a survey"""
        STATUS_CHOICES = (
                ('A', 'Active'),
                ('C', 'Complete'),
                ('D', 'Development'),
        )

        TYPE_CHOICES = (
                ('A', 'Public'),
                ('B', 'Private'),
        )

        STATUS_DBS = (
                ('A', 'MySQL'),
                ('B', 'MS SQL'),
        )

        STATUS_OS = (
                ('A', 'Linux'),
                ('B', 'OS X'),
                ('C', 'Unix'),
                ('D', 'Windows'),
        )

        STATUS_LANG = (
                ('A', 'English'),
        )

        STATUS_ENC = (
                ('A', 'Autodetect'),
                ('B', 'Utf8 (UTF-8 unicode)'),
                ('C', 'ISO Latin 1 (latin1)'),
        )

        name = forms.CharField(max_length=50, widget=forms.TextInput(attrs=
{'size':'50'}))
        client = forms.ModelChoiceField(User.objects.all())
        gen_source_path = forms.CharField(max_length=100,
widget=forms.TextInput(attrs={'size':'50'}))
        gen_dest_path = forms.CharField(max_length=100 ,widget=forms.TextInput
(attrs={'size':'50'}))
        url = forms.CharField(max_length=100, required=False,
widget=forms.TextInput(attrs={'size':'50'}))
        db_type = forms.CharField(max_length=1, widget=forms.Select
(choices=STATUS_DBS))
        db_name = forms.CharField(max_length=50 ,widget=forms.TextInput(attrs=
{'size':'50'}))
        table_name = forms.CharField(max_length=50 ,widget=forms.TextInput
(attrs={'size':'50'}))
        cookie_name = forms.CharField(max_length=50 ,widget=forms.TextInput
(attrs={'size':'50'}))
        header_title1 = forms.CharField(max_length=50 ,widget=forms.TextInput
(attrs={'size':'50'}))
        header_title2 = forms.CharField(max_length=50 ,widget=forms.TextInput
(attrs={'size':'50'}))
        header_title3 = forms.CharField(max_length=50 ,widget=forms.TextInput
(attrs={'size':'50'}))
        footer_title1 = forms.CharField(max_length=50 ,widget=forms.TextInput
(attrs={'size':'50'}))
        footer_title2 = forms.CharField(max_length=50 ,widget=forms.TextInput
(attrs={'size':'50'}))
        status = forms.CharField(max_length=1, widget=forms.Select
(choices=STATUS_CHOICES))
        survey_type = forms.CharField(max_length=1, widget=forms.Select
(choices=TYPE_CHOICES))
        operating_system = forms.CharField(max_length=1, widget=forms.Select
(choices=STATUS_OS))
        language = forms.CharField(max_length=1, widget=forms.Select
(choices=STATUS_LANG))
        encoding = forms.CharField(max_length=1, widget=forms.Select
(choices=STATUS_ENC))

I tried commenting out the foreign key to the user but that made no
difference. I must be doing something stupid here (obvious hopefully).

Can anyone tell me what the problem is?

Thanks,

Peter


--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to