Re: Unable to add two Numbers

2010-08-29 Thread Steve Holden
On 8/29/2010 1:20 PM, Harbhag Singh Sohal wrote:
> i am the new user of Django, i try the tutorials of  django wesite
> http://docs.djangoproject.com/en/1.2/intro/tutorial01/
>  
> 
> 
> Now i create a application in django to add two numbers, After filling form.
> and store the values of two inputs and output after add two numbers in
> databases.
> 
> me able to create form and database using model.py file and using template,
> but me face problem to store the two input value in database after
> filling in form text box.
> 
> me try use request.POST function to get the value, but me also fail to
> get the form values.
> 
> Please suggest me how i get the value from form text fields and store
> in database.
> 
Harbagh:

Your question is the approximate equivalent of:

  "I have a car, but when I try to drive it it doesn't work"

You don't show any code, you don't give us any error messages, you don't
describe the failure mode at all. You simply say that you fail tp get
the form values and you "face a problem" in storing the information in
the database.

Is it that you don't know how to write the code, or that the code you
have written isn't working.

regards
 Steve
-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Unable to add two Numbers

2010-08-29 Thread Harbhag Singh Sohal
On Sun, Aug 29, 2010 at 10:56 PM, Steve Holden  wrote:

> On 8/29/2010 1:20 PM, Harbhag Singh Sohal wrote:
> > i am the new user of Django, i try the tutorials of  django wesite
> > http://docs.djangoproject.com/en/1.2/intro/tutorial01/
> >
> >
> >
> > Now i create a application in django to add two numbers, After filling
> form.
> > and store the values of two inputs and output after add two numbers in
> > databases.
> >
> > me able to create form and database using model.py file and using
> template,
> > but me face problem to store the two input value in database after
> > filling in form text box.
> >
> > me try use request.POST function to get the value, but me also fail to
> > get the form values.
> >
> > Please suggest me how i get the value from form text fields and store
> > in database.
> >
> Harbagh:
>
> Your question is the approximate equivalent of:
>
>  "I have a car, but when I try to drive it it doesn't work"
>
> You don't show any code, you don't give us any error messages, you don't
> describe the failure mode at all. You simply say that you fail tp get
> the form values and you "face a problem" in storing the information in
> the database.
>
> Is it that you don't know how to write the code, or that the code you
> have written isn't working.
>
>
>
I have written the code
model.py
from django.db import models

class Math(models.Model):
   input1 = models.IntegerField()
   input2 = models.IntegerField()
   output = models.IntegerField()

Views.py file

from django.template import RequestContext
from django.shortcuts import render_to_response
from mysite.maths.models import Math
from django.http import Http404
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect, HttpResponse
from django.template import RequestContext

def index(request):
   latest_math_list = Math.objects.all().order_by('
id')[:5]
   return render_to_response('maths/index.html', {'latest_math_list':
latest_math_list})

def detail(request, math_id):
   p = get_object_or_404(Math, pk=math_id)
   return render_to_response('maths/detail.html', {'math': p},
  context_instance=RequestContext(request))
def results(request, math_id):
   p = get_object_or_404(Math, pk=math_id)
   return render_to_response('maths/results.html', {'math': p})

def vote(request, math_id):
   p = get_object_or_404(Math, pk=math_id)
   try:
   selected_input1 = p.math_set.get(pk=request.POST['input1'])
   selected_input2 = p.math_set.get(pk=request.POST['input2'])
   except (KeyError, Math.DoesNotExist):
  # Redisplay the poll voting form.
   return render_to_response('maths/detail.html', {
   'poll': p,
   'error_message': "You didn't fill a value.",
   }, context_instance=RequestContext(request))
   else:
   selected_output = selected_input1 + selected_input2
   selected_output.save()

   return HttpResponseRedirect(reverse('mysite.maths.views.results',
args=(p.id

,)))

problem is in def vote function.


-- 
Harbhag Singh Sohal
Website : http://harbhag.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Unable to add two Numbers

2010-08-29 Thread Harbhag Singh Sohal
On Sun, Aug 29, 2010 at 11:22 PM, Harbhag Singh Sohal <
harbhag.so...@gmail.com> wrote:

>
>
> On Sun, Aug 29, 2010 at 10:56 PM, Steve Holden wrote:
>
>> On 8/29/2010 1:20 PM, Harbhag Singh Sohal wrote:
>> > i am the new user of Django, i try the tutorials of  django wesite
>> > http://docs.djangoproject.com/en/1.2/intro/tutorial01/
>> >
>> >
>> >
>> > Now i create a application in django to add two numbers, After filling
>> form.
>> > and store the values of two inputs and output after add two numbers in
>> > databases.
>> >
>> > me able to create form and database using model.py file and using
>> template,
>> > but me face problem to store the two input value in database after
>> > filling in form text box.
>> >
>> > me try use request.POST function to get the value, but me also fail to
>> > get the form values.
>> >
>> > Please suggest me how i get the value from form text fields and store
>> > in database.
>> >
>> Harbagh:
>>
>> Your question is the approximate equivalent of:
>>
>>  "I have a car, but when I try to drive it it doesn't work"
>>
>> You don't show any code, you don't give us any error messages, you don't
>> describe the failure mode at all. You simply say that you fail tp get
>> the form values and you "face a problem" in storing the information in
>> the database.
>>
>> Is it that you don't know how to write the code, or that the code you
>> have written isn't working.
>>
>>
>>
> I have written the code
> model.py
> from django.db import models
>
> class Math(models.Model):
>input1 = models.IntegerField()
>input2 = models.IntegerField()
>output = models.IntegerField()
>
> Views.py file
>
> from django.template import RequestContext
> from django.shortcuts import render_to_response
> from mysite.maths.models import Math
> from django.http import Http404
> from django.shortcuts import render_to_response, get_object_or_404
> from django.http import HttpResponseRedirect, HttpResponse
> from django.template import RequestContext
>
> def index(request):
>latest_math_list = Math.objects.all().order_by('
> id')[:5]
>return render_to_response('maths/index.html', {'latest_math_list':
> latest_math_list})
>
> def detail(request, math_id):
>p = get_object_or_404(Math, pk=math_id)
>return render_to_response('maths/detail.html', {'math': p},
>   context_instance=RequestContext(request))
> def results(request, math_id):
>p = get_object_or_404(Math, pk=math_id)
>return render_to_response('maths/results.html', {'math': p})
>
> def vote(request, math_id):
>p = get_object_or_404(Math, pk=math_id)
>try:
>selected_input1 = p.math_set.get(pk=request.POST['input1'])
>selected_input2 = p.math_set.get(pk=request.POST['input2'])
>except (KeyError, Math.DoesNotExist):
>   # Redisplay the poll voting form.
>return render_to_response('maths/detail.html', {
>'poll': p,
>'error_message': "You didn't fill a value.",
>}, context_instance=RequestContext(request))
>else:
>selected_output = selected_input1 + selected_input2
>selected_output.save()
>
>return HttpResponseRedirect(reverse('mysite.maths.views.results',
> args=(p.id
>
> ,)))
>
> problem is in def vote function.
>
>
> for code:-
http://202.164.53.116/~jagdeep/mysite/maths/


http://202.164.53.116/~jagdeep/mytemplates/maths/



and also check site
http://202.164.53.116/django/maths/2/





-- 
Harbhag Singh Sohal
Website : http://harbhag.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Unable to add two Numbers

2010-08-29 Thread Daniel Roseman
> I have written the code
> model.py
> from django.db import models
>
> class Math(models.Model):
>    input1 = models.IntegerField()
>    input2 = models.IntegerField()
>    output = models.IntegerField()
>
> Views.py file
>
> from django.template import RequestContext
> from django.shortcuts import render_to_response
> from mysite.maths.models import Math
> from django.http import Http404
> from django.shortcuts import render_to_response, get_object_or_404
> from django.http import HttpResponseRedirect, HttpResponse
> from django.template import RequestContext
>
> def index(request):
>    latest_math_list = Math.objects.all().order_by('
> id')[:5]
>    return render_to_response('maths/index.html', {'latest_math_list':
> latest_math_list})
>
> def detail(request, math_id):
>    p = get_object_or_404(Math, pk=math_id)
>    return render_to_response('maths/detail.html', {'math': p},
>                               context_instance=RequestContext(request))
> def results(request, math_id):
>    p = get_object_or_404(Math, pk=math_id)
>    return render_to_response('maths/results.html', {'math': p})
>
> def vote(request, math_id):
>    p = get_object_or_404(Math, pk=math_id)
>    try:
>        selected_input1 = p.math_set.get(pk=request.POST['input1'])
>        selected_input2 = p.math_set.get(pk=request.POST['input2'])
>    except (KeyError, Math.DoesNotExist):
>   # Redisplay the poll voting form.
>        return render_to_response('maths/detail.html', {
>            'poll': p,
>            'error_message': "You didn't fill a value.",
>        }, context_instance=RequestContext(request))
>    else:
>        selected_output = selected_input1 + selected_input2
>        selected_output.save()
>
>        return HttpResponseRedirect(reverse('mysite.maths.views.results',
> args=(p.id
>
> ,)))
>
> problem is in def vote function.

And you still don't tell us what the actual problem is. There are two
obvious issues with the code you've posted, but you haven't told us
which issue you are encountering.

Firstly, you get a Math object `p`, then get another two Math
instances via `p.math_set.get()`. With the code you've posted, the
Math model doesn't have a `math_set` attribute - for that to exist,
the model would need to have a foreign key relationship to self, which
it doesn't have. It's not clear what you are trying to do here.

Secondly, presuming that works, selected_input1 and selected_input2
are both instances of the Math model. You haven't defined an __add__
method on Math, so adding two instances makes no sense. If you just
want to add two numbers and save the result, just do that, don't try
to add the instances.
--
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-us...@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: Unable to add two Numbers

2010-08-29 Thread Kenneth Gonsalves
On Sun, 2010-08-29 at 22:50 +0530, Harbhag Singh Sohal wrote:
> me try use request.POST function to get the value, but me also fail to
> get the form values.
> 
> Please suggest me how i get the value from form text fields and store
> in database. 

please post your code
-- 
regards
Kenneth Gonsalves

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Unable to add two Numbers

2010-08-29 Thread Harbhag Singh Sohal
On Mon, Aug 30, 2010 at 7:21 AM, Kenneth Gonsalves wrote:

> On Sun, 2010-08-29 at 22:50 +0530, Harbhag Singh Sohal wrote:
> > me try use request.POST function to get the value, but me also fail to
> > get the form values.
> >
> > Please suggest me how i get the value from form text fields and store
> > in database.
>
> please post your code
> --
> regards
> Kenneth Gonsalves
>
> I have already posted the code in the above posts . For more details please
check the links above .
-- 
Harbhag Singh Sohal
Website : http://harbhag.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Unable to add two Numbers

2010-08-29 Thread Harbhag Singh Sohal
sir, i am very new in  django?

 so, please  sir help.
tell me, how to code Views.py file  to solve my problem.
 I am confused.

 I have read tutorial / documentation at _, but could not get a
 bare minimum example to code Views.py, if there is any, kindly help me
 by posting link.

I just only want get to values from form, store in database, then add
these values
and finally store the output in database

Thanks




-- 
Harbhag Singh Sohal
Website : http://harbhag.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Unable to add two Numbers

2010-08-29 Thread Kenneth Gonsalves
On Mon, 2010-08-30 at 10:06 +0530, Harbhag Singh Sohal wrote:
> I have read tutorial / documentation

no use reading it - please do the tutorial step by step until you make a
complete web application as shown in the tutorial. Then you will be able
to understand how to add the numbers.
-- 
regards
Kenneth Gonsalves

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Unable to add two Numbers

2010-08-30 Thread Harbhag Singh Sohal
On Mon, Aug 30, 2010 at 10:14 AM, Kenneth Gonsalves wrote:

> On Mon, 2010-08-30 at 10:06 +0530, Harbhag Singh Sohal wrote:
> > I have read tutorial / documentation
>
> no use reading it - please do the tutorial step by step until you make a
> complete web application as shown in the tutorial. Then you will be able
> to understand how to add the numbers.
> --
> regards
> Kenneth Gonsalves
>
>  Thanks everyone replying . I think I need to do read the tutorial
thoroughly again . Now I will comeback after reading and doing everything
from scratch .

-- 
Harbhag Singh Sohal
Website : http://harbhag.wordpress.com/

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