On Thu, Dec 10, 2009 at 11:21 AM, Kenneth McDonald
<[email protected]> wrote:
>
>> And the code to create and validate the form is...?  That might help
>> in figuring out what is wrong.
>>
> Sure. It's just:
>
>
>
> def buysell(request):
>     form = BuySellForm()
>     return render_to_response('buysellform.html', {'form': form})

Here is the problem. As of now, `form` is an unbound form (see docs
[1]). You need to do something like:

form = BuySellForm(request.POST)

This will trigger all the validation functions, including
clean_shares. You should rewrite your `buysell` view to be something
along the lines of:

def buysell(request):
    if request.method == "POST":
        form = BuySellForm(request.POST)
        if form.is_valid():
            #do something...
        else:
            #return an error
     else:
         form = BuySellForm()
         return render_to_response('buysellform.html', {'form': form})

Also, unless you haven't posted all the code from BuySellForm's
definition, clean_shares will throw an error because there is no field
called `data` defined in the form.

[1] - 
http://docs.djangoproject.com/en/dev/ref/forms/api/#bound-and-unbound-forms

>
>
>
> in file 'buysell.py', and is referenced as http://.../buysell, as per
> the urls.py file:
>
>
>
> from django.conf.urls.defaults import *
> from mysite import buysell
>
> # Uncomment the next two lines to enable the admin:
> # from django.contrib import admin
> # admin.autodiscover()
>
> urlpatterns = patterns('',
>     (r'^buysell/$', buysell.buysell),
>     (r'^boughtsold/$', buysell.boughtsold),
>
>
> and for good measure the HTML is:
>
>
>
> <html><head/>
> <body>
> <form method="post" action="/boughtsold/">
>        Symbol:<input type="text", name="symbol" value="{{ symbol }}"><p/>
>        Shares:<input type="text", name="shares"><p/>
>        Price:<input type="text", name="price"><p/>
>        <input type="submit", value="buy">
>        <input type="submit", value="sell">
> </form>
> </body>
> </html>
>
>
> Thanks!
> Ken
>
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to [email protected].
> 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.
>
>
>



-- 

Best,

R

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
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