List Info

Thread: Newforms Attribute Errors




Newforms Attribute Errors
country flaguser name
United States
2007-06-26 13:22:29
Hopefully you guys can spot an error I've not been able to.
This is
the error I get:

AttributeError at /vendor/Chef/1/
'Order_DetailForm' object has no attribute 'save'
Request Method: POST
Request URL: http://192.1
68.1.104:8000/vendor/Chef/1/
Exception Type: AttributeError
Exception Value: 'Order_DetailForm' object has no attribute
'save'

My view:
from django.http import Http404, HttpResponse,
HttpResponseRedirect
from django.newforms import form_for_model

def vendor(request, vendor_name, vendor_id):
  OrderForm = form_for_model(Order)
  OrderDetailForm = form_for_model(Order_Detail)
  cart_id = find_order(manager_id)

  if request.method == 'POST':
    form = OrderDetailForm(request.POST)
    if cart_id != 0:
      if form.is_valid():.
        new_detail = form.save(commit=False)
        return HttpResponseRedirect(".")
  else:
    form = OrderDetailForm(detail_form_data)

  return render_to_response("vendor/" +
vendor_name + ".html",
locals())

I tried .is_bound and a similar problem came up. Basically I
can't
access some functions and fields that're available from
form_for_model. I also tried commenting out the save,
creating valid =
form.is_valid() and printing it out. It printed out
"True", therefore
my form is valid, but the thing is I cannot save.

Also, the error "'Order_DetailForm' object has no
attribute 'save'"
doesn't look right. Isn't it supposed to be
"'OrderDetailForm' object
has no attribute 'save'" because I defined
OrderDetailForm, not
Order_DetailForm?

Thanks for the help


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Newforms Attribute Errors
country flaguser name
Australia
2007-06-26 22:50:44
On Tue, 2007-06-26 at 11:22 -0700, robo wrote:
> Hopefully you guys can spot an error I've not been able
to. This is
> the error I get:
> 
> AttributeError at /vendor/Chef/1/
> 'Order_DetailForm' object has no attribute 'save'
> Request Method: POST
> Request URL: http://192.1
68.1.104:8000/vendor/Chef/1/
> Exception Type: AttributeError
> Exception Value: 'Order_DetailForm' object has no
attribute 'save'
> 

[..]
> Also, the error "'Order_DetailForm' object has no
attribute 'save'"
> doesn't look right. Isn't it supposed to be
"'OrderDetailForm' object
> has no attribute 'save'" because I defined
OrderDetailForm, not
> Order_DetailForm?

Yes, that is unexpected.

This problem will be a lot easier to debug if you can post
the full
traceback, rather than just the final line that is at the
top of the
debug page.

Look on the error page. There is a link called
"cut-and-paste view".
Click on that and then cut-and-paste the traceback it shows.
That might
provide some more clues.

Thanks,
Malcolm

-- 
The hardness of butter is directly proportional to the
softness of the
bread. 
http://www.pointy-s
tick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Newforms Attribute Errors
country flaguser name
United States
2007-06-27 10:12:08
Hi Malcolm,

This is my traceback errors from copy&paste:

Traceback (most recent call last):
File
"/usr/lib/python2.4/site-packages/django/core/handlers/
base.py"
in get_response
  74. response = callback(request, *callback_args,
**callback_kwargs)
File
"/www/htdocs/gfs_chefrevival/../gfs_chefrevival/shop/vi
ews.py" in
vendor
  133. new_detail = form.save()

  AttributeError at /vendor/Chef/1/
  'Order_DetailForm' object has no attribute 'save'

-------------------
This is traceback errors from interactive view:

133.     new_detail = form.save()
Local vars:

Variable                  Value
----------------------------------------
OrderDetailForm      <class
'django.newforms.models.Order_DetailForm'>
cart_id                    1L
form                       
<django.newforms.models.Order_DetailForm
object at 0xa6b48d6c>


I think it has something to do with how I'm importing. This
is my
complete import statements:

from django.shortcuts import render_to_response,
get_object_or_404
from django.contrib import *
from gfs_chefrevival.store.models import *
from gfs_chefrevival.products.models import *
from gfs_chefrevival.vendors.models import Vendor
from django.http import *
from django.db import models
from django import newforms as forms             
<---------
import datetime
from django.contrib.auth.models import User

Hopefully you guys can get more insight to this.
Thanks!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Newforms Attribute Errors
country flaguser name
United States
2007-06-27 14:05:50
I've also tried abandoning form_for_model and created my own
custom
form like so in forms.py:

from django import newforms as forms
from django.newforms.widgets import *

class OrderDetailForm(forms.Form):
  order = forms.IntegerField()
  quantity = forms.IntegerField()
  unitPrice = FloatField(label='Price', max_digits=10,
decimal_places=2)
  lineItemPrice = FloatField(label='Line Item Price',
required=False,
max_digits=10, decimal_places=2)
  item = forms.IntegerField()
  size = forms.ChoiceField(choices=SIZE)
  timestamp = forms.DateTimeField(required=False)
  vendor = forms.IntegerField()

----------------------
Then in my view:

from django.shortcuts import render_to_response,
get_object_or_404
from django.contrib import *
from gfs_chefrevival.store.models import *
from gfs_chefrevival.shop.forms import OrderDetailForm
from gfs_chefrevival.products.models import *
from gfs_chefrevival.vendors.models import Vendor
from django.contrib.auth.models import User
from django.http import *
from django import newforms as forms
import datetime

  detail_form_data = {
      #'timestamp': datetime.datetime.now(),
      'vendor': vendor_id,
      'unitPrice': 5.23,
      'lineItemPrice': 1.90,
      'quantity': 1,
      'order': 1,
      'size': "M",
      'item': 5
  }

def vendor(request, vendor_name, vendor_id):
  if request.method == 'POST':
    form = OrderDetailForm(request.POST)
    if form.is_valid():
      form.save()
      return HttpResponseRedirect(".")

  else:
    form = OrderDetailForm(detail_form_data)

------------------
But even using custom forms I get errors:

AttributeError at /vendor/Chef/1/
'lineItemPrice' object has no attribute 'save'
Request Method: POST
Request URL: http://192.1
68.1.104:8000/vendor/Chef/1/
Exception Type: AttributeError
Exception Value: 'lineItemPrice' object has no attribute
'save'
Exception Location:
/www/htdocs/gfs_chefrevival/../gfs_chefrevival/
shop/views.py in vendor, line 131

This error shows up for EVERY form field in my forms.py
(I've
commented out one by one).

FYI, I'm using Django's development version (0.96-pre),
could this be
a problem?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Newforms Attribute Errors
country flaguser name
United States
2007-06-27 20:26:35
In python shell I typed:
>> from gfs_chefrevival.shop.forms import
OrderDetailForm
>> from django import newforms as forms
>> f = OrderDetailForm()
>> f.is_bound

I get the error:

Traceback (most recent call last):
  File "<console>", line 1, in ?
AttributeError: 'lineItemPrice' object has no attribute
'is_bound'
>>>

What's the problem? Can anyone tell me?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Newforms Attribute Errors
country flaguser name
Australia
2007-06-27 23:20:26
On Wed, 2007-06-27 at 12:05 -0700, robo wrote:
[...]
> ------------------
> But even using custom forms I get errors:
> 
> AttributeError at /vendor/Chef/1/
> 'lineItemPrice' object has no attribute 'save'
> Request Method: POST
> Request URL: http://192.1
68.1.104:8000/vendor/Chef/1/
> Exception Type: AttributeError
> Exception Value: 'lineItemPrice' object has no
attribute 'save'
> Exception Location:
/www/htdocs/gfs_chefrevival/../gfs_chefrevival/
> shop/views.py in vendor, line 131
> 
> This error shows up for EVERY form field in my forms.py
(I've
> commented out one by one).
> 
> FYI, I'm using Django's development version (0.96-pre),
could this be
> a problem?

If it says "0.96-pre" you aren't using the
development version. You are
using something from before the last release. However, even
if you made
a typo there and are really using 0.97-pre, there are no
known huge bugs
in the form handling code. Lots of people are using the
development
version. You are using some code that is at least a month or
two old,
though, since FloatField no longer takes max_digits and
decimal_places
in trunk.

I have no guess as to what is going wrong here .You're just
going to
have use normal debugging techniques: put print statements
into the
code, for example and check that things are the types they
should be.
Read the Django source where it is failing and work out what
it is
expecting. Reduce your problem case to an example that is as
small as
possible so you don't have to worry about extra stuff
getting in the
way. Things like that.

You are getting some fairly explicit error messages, so
working out what
is trying to call save() on a form field (and why) is going
to go a long
way towards solving this.

Regards,
Malcolm

-- 
What if there were no hypothetical questions? 
http://www.pointy-s
tick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Newforms Attribute Errors
country flaguser name
United States
2007-06-28 02:54:14
You tried, thanks!

The errors I get come before any major piece of code. They
come after
some simple statements:
OrderDetailForm = form_for_model(Order_Detail)
f = OrderDetailForm()
f.save()
f.is_bound

which means my 0.96-pre (not a typo  ) version
might not be up to
the challenge of newforms. I will upgrade to the development
version
and see if the errors go away.

FYI, the FloatField I used was a class I created, not
provided by
Django, therefore it could take max_digits and
decimal_places.

Quick question, what is the difference between
form_for_model,
forms.form_for_model, and forms.models.form_for_model? I
have seen all
3 in use.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-7]

about | contact  Other archives ( Real Estate discussion Medical topics )