Re: Created Form - now code works to edit object but add gets NoneType' object is not callable

2009-01-15 Thread Peter Bailey

Well I experimented with your tips Daniel, and put this in my forms
file:

class SurveyForm(forms.ModelForm):

name = forms.CharField(max_length=50, widget=forms.TextInput(attrs=
{'size':'50'}))

class Meta:
model = Survey

And it works. I assume I just add the ones above that I want to change
the defaults on? Much DRYer - ah

Thank You


On Jan 15, 1:38 pm, Peter Bailey  wrote:
> Thanks for the tips Dan, I thought the DRY thing could not be right.
> Not sure I understand tho - I originally made the form with just the
> inner Meta class definition - do you do that and then override things
> that need to change (e.g. where I want to use a longer TextInput
> widget or whatever.
>
> Things worked fine until I changed to the above form definition so
> that I could make mods to the default output.
>
> re "client = forms.ModelChoiceField(User.objects.all())", that is the
> line I mentioned above that I commented out because I suspected it
> too. I tried your change, still not working
>
> Here is the traceback. Thanks Dan and Andrew, listening while I am
> being so verbose, but I wanted to convey as much info as possible. I
> am learning django and python together, and it gets to be pretty
> boggling sometimes, although it is the most fun developing I have had
> in years. I appreciate you taking your time looking at this.
>
> Environment:
>
> Request Method: GET
> Request URL:http://localhost:8000/surveyadd/
> Django Version: 1.1 pre-alpha SVN-9734
> Python Version: 2.5.1
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'django.contrib.admin',
>  'generator.surveys']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>  'django.middleware.doc.XViewMiddleware')
>
> Traceback:
> File "/Library/Python/2.5/site-packages/django/core/handlers/base.py"
> in get_response
>   86.                 response = callback(request, *callback_args,
> **callback_kwargs)
> File "/Users/peterbailey/pywork/generator/../generator/surveys/
> views.py" in surveyadd
>   137.         form = SurveyForm()
> File "/Library/Python/2.5/site-packages/django/forms/models.py" in
> __init__
>   212.             self.instance = opts.model()
>
> Exception Type: TypeError at /surveyadd/
> Exception Value: 'NoneType' object is not callable
>
> Hope that is all the traceback info you need.
>
> Peter
>
> On Jan 15, 1:16 pm, Daniel Roseman 
> wrote:
>
> > On Jan 15, 5:35 pm, Peter Bailey  wrote:
>
> > > 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
>
> > 
>
> > > 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
>
> > Why have you repeated all the definitions from the model in your form?
> > As you say, that isn't very DRY, but there's no reason to do it at
> > all.
>
> > It would have been helpful to have posted the full traceback. I
> > suspect your error is coming from this line:
> >         client = forms.ModelChoiceField(User.objects.all())
> > which should be
> >         client = forms.ModelChoiceField(queryset=User.objects.all())
> > However, as i note above, you don't need the line - or any of the
> > field declarations - at all. You do, however, need an inner Meta class
> > which defines the model the form belongs to (Survey).
>
> > --
> > DR.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Created Form - now code works to edit object but add gets NoneType' object is not callable

2009-01-15 Thread Peter Bailey

Thanks Andy


On Jan 15, 1:50 pm, Andy Mckay  wrote:
> I don't think you are defining the ModelForm correctly, the whole  
> point is that Django creates the fields for you. If you look at:
>
> http://docs.djangoproject.com/en/dev/topics/forms/modelforms
>
> This is the key difference between a ModelForm and a normal form:
>
> http://docs.djangoproject.com/en/dev/topics/forms/#form-objects
>
> You'll see there are no field definitions and there is instead a  
> pointer through class Meta: to the model. The form is trying to create  
> the model and failing. A better form for you would be:
>
> class SurveyForm(forms.ModelForm):
>      class Meta:
>          model = Survey
>
> (add in your import statement so it knows what Survey is).
>
> Cheers
> --
>    Andy McKay
>    ClearWind Consulting:www.clearwind.ca
>    Blog:www.agmweb.ca/blog/andy
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Created Form - now code works to edit object but add gets NoneType' object is not callable

2009-01-15 Thread Andy Mckay

I don't think you are defining the ModelForm correctly, the whole  
point is that Django creates the fields for you. If you look at:

http://docs.djangoproject.com/en/dev/topics/forms/modelforms

This is the key difference between a ModelForm and a normal form:

http://docs.djangoproject.com/en/dev/topics/forms/#form-objects

You'll see there are no field definitions and there is instead a  
pointer through class Meta: to the model. The form is trying to create  
the model and failing. A better form for you would be:

class SurveyForm(forms.ModelForm):
 class Meta:
 model = Survey

(add in your import statement so it knows what Survey is).

Cheers
--
   Andy McKay
   ClearWind Consulting: www.clearwind.ca
   Blog: www.agmweb.ca/blog/andy


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Created Form - now code works to edit object but add gets NoneType' object is not callable

2009-01-15 Thread Peter Bailey

Thanks for the tips Dan, I thought the DRY thing could not be right.
Not sure I understand tho - I originally made the form with just the
inner Meta class definition - do you do that and then override things
that need to change (e.g. where I want to use a longer TextInput
widget or whatever.

Things worked fine until I changed to the above form definition so
that I could make mods to the default output.

re "client = forms.ModelChoiceField(User.objects.all())", that is the
line I mentioned above that I commented out because I suspected it
too. I tried your change, still not working

Here is the traceback. Thanks Dan and Andrew, listening while I am
being so verbose, but I wanted to convey as much info as possible. I
am learning django and python together, and it gets to be pretty
boggling sometimes, although it is the most fun developing I have had
in years. I appreciate you taking your time looking at this.

Environment:

Request Method: GET
Request URL: http://localhost:8000/surveyadd/
Django Version: 1.1 pre-alpha SVN-9734
Python Version: 2.5.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'generator.surveys']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Traceback:
File "/Library/Python/2.5/site-packages/django/core/handlers/base.py"
in get_response
  86. response = callback(request, *callback_args,
**callback_kwargs)
File "/Users/peterbailey/pywork/generator/../generator/surveys/
views.py" in surveyadd
  137. form = SurveyForm()
File "/Library/Python/2.5/site-packages/django/forms/models.py" in
__init__
  212. self.instance = opts.model()

Exception Type: TypeError at /surveyadd/
Exception Value: 'NoneType' object is not callable


Hope that is all the traceback info you need.

Peter





On Jan 15, 1:16 pm, Daniel Roseman 
wrote:
> On Jan 15, 5:35 pm, Peter Bailey  wrote:
>
> > 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
>
> 
>
> > 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
>
> Why have you repeated all the definitions from the model in your form?
> As you say, that isn't very DRY, but there's no reason to do it at
> all.
>
> It would have been helpful to have posted the full traceback. I
> suspect your error is coming from this line:
>         client = forms.ModelChoiceField(User.objects.all())
> which should be
>         client = forms.ModelChoiceField(queryset=User.objects.all())
> However, as i note above, you don't need the line - or any of the
> field declarations - at all. You do, however, need an inner Meta class
> which defines the model the form belongs to (Survey).
>
> --
> DR.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Created Form - now code works to edit object but add gets NoneType' object is not callable

2009-01-15 Thread Daniel Roseman

On Jan 15, 5:35 pm, Peter Bailey  wrote:
> 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



> 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

Why have you repeated all the definitions from the model in your form?
As you say, that isn't very DRY, but there's no reason to do it at
all.

It would have been helpful to have posted the full traceback. I
suspect your error is coming from this line:
client = forms.ModelChoiceField(User.objects.all())
which should be
client = forms.ModelChoiceField(queryset=User.objects.all())
However, as i note above, you don't need the line - or any of the
field declarations - at all. You do, however, need an inner Meta class
which defines the model the form belongs to (Survey).

--
DR.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Created Form - now code works to edit object but add gets NoneType' object is not callable

2009-01-15 Thread Andrew Mckay


On 15-Jan-09, at 9:35 AM, Peter Bailey wrote:
> 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".

That's a lot to read through and not too helpful. What might be more  
useful is the traceback (so we now what the error is) and the code  
where the error occurs (which the traceback tells you), presumably  
your view.
--
   Andy McKay
   www.clearwind.ca

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Created Form - now code works to edit object but add gets NoneType' object is not callable

2009-01-15 Thread Peter Bailey

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