Re: Foreign Key don't work for me
On Thu, May 17, 2012 at 6:09 AM, Jon Paugh <jpaugh@gmx.us> wrote:
> Ah. I believe, the Amount.job_no (i.e. the foreign key) should not be filled
> with the id of the Client object, but with the actual client object, that
> is,
>
> job_no = Client.objects.get(cd['job_no'])
>
> That matches the abstract relationship of, "This Client corresponds to this
> Amount.", then Django takes care of the db details, i.e. finding the pk.
>
Changed the views, even then, tasted no success.
I have changed the views to:
def report_calculation(request):
id = ClientJob.objects.aggregate(Max('job_no'))
maxid =id['job_no__max']
if request.method == 'POST':
form =AmountForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
#job_no = cd['job_no']
type = cd['type'] #sandeep
lab = cd['lab']
field = cd['field']
other_field = cd['other_field']
job_no = ClientJob.objects.get(cd['job_no'])
p = Amount(job_no=job_no,date=datetime.date.today(),type=type,lab=lab,field=field,other_field=other_field,)
p.save()
return render_to_response('automation/job_ok.html', {'form': form,
'maxid':maxid}, context_instance=RequestContext(request))
else:
form = AmountForm()
return render_to_response('automation/job_add.html', {'form': form,
'maxid': maxid}, context_instance=RequestContext(request))
--
Sandeep Kaur
E-Mail: mkaurkhalsa@gmail.com
Blog: sandymadaan.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-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home