I try to get the max value of id from database using max() function
but a face this error.
{
TypeError at /add_db/

'builtin_function_or_method' object is not iterable

Request Method:         POST
Request URL:    http://localhost/django/add_db/
Django Version:         1.2.1
Exception Type:         TypeError
Exception Value:        'builtin_function_or_method' object is not iterable

Exception Location:     /home/jagdeep/mysite/add_db/views.py in add_db,
line 19
Python Executable:      /usr/bin/python
}

model.py
from django.db import models
from django.forms import ModelForm

class Input(models.Model):
    input1 = models.FloatField()
    input2 = models.FloatField()

class Output(models.Model):
        out = models.ForeignKey(Input)
        output = models.FloatField()

class InputForm(ModelForm):
    class Meta :
        model = Input

class OutputForm(ModelForm):
    class Meta :
        model = Output



View.py
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404
from mysite.add_db.models import *
from django.template import RequestContext
from django.core.urlresolvers import reverse


def add_db(request):
    if request.method == 'POST':
        form = InputForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            input1 = cd['input1']
            input2 = cd['input2']
            form.save()
            form_output = OutputForm()
            output = input1 + input2
            p = get_object_or_404(Input, pk=max(id))
          form_output_final = p.output_set.create(output=output)
            return render_to_response('add_db/output.html', {'form':
form, 'input1':input1, 'input2':input2, 'output':output},
context_instance=RequestContext(request))
    else:
        form = InputForm()
    return render_to_response('add_db/add.html', {'form': form},
context_instance=RequestContext(request))


I want to get the latest or maximum  "Id" value of INPUT table from
database.

please help

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

Reply via email to