On Mon, Apr 1, 2013 at 12:48 PM, Siddharth Ghumre
<[email protected]> wrote:
> Hi
>
> As per my view your client query is returning more than one rows from your
> database.
> Suppose your job = 1 which you are getting from your Report table and the
> query ( Job.objects.all().filter(
> client=job)......)fetches two or more than two records from your 'job'
> table.
>
> Now there can be two scenarios:-
> 1.You are looking for a single record to be displayed after executing
> (Job.objects.all().filter(client=job)......)
> In this case you need to use filter query like
> Job.objects.all().filter(Q(client=job)&Q(something=something)&Q(something=something)...)
> which will give you a unique row as per your filter criteria.
>
> 2.You are looking for multiple records to be displayed:-
> In this case you need to add a for after your query.
> Like
>  table1=[]
>  client = Job.objects.all().filter(client=job)
>  for i in client:
>     client__client__first_name = i.first_name
>     client__client__middle_name = i.middle_name
>     ...
>     ...
>     ...
>
>     table1.append({"client__client__first_name":client__client__first_name,"
> client__client__middle_name": client__client__middle_name,.........})
>
>
>  temp = {'client':table1, 'cubee':cubee, 'Head':Head,
> 'organisation':organisation,'department':department,}
>
>
> I hope this might solve your problem.


Thanks Siddharth, for the explanation.
>
>
>
>
>
> On Mon, Apr 1, 2013 at 2:51 AM, Satinderpal Singh
> <[email protected]> wrote:
>>
>> I have the following error in my project
>>
>> (1242, 'Subquery returns more than 1 row')
>>
>> my views are as given below
>>
>> def result_cube(request):
>>         Id = Cube.objects.aggregate(Max('Report_id'))
>>         ID = Id['Report_id__max']
>>         cubee = Cube.objects.filter(Report_id = ID)
>>         Id = Report.objects.aggregate(Max('id'))
>>         ID = Id['id__max']
>>         Head = Report.objects.filter(id = ID)
>>         organisation = Organisation.objects.all().filter(id = 1)
>>         department = Department.objects.all().filter(id = 1)
>>
>>         Id = Report.objects.aggregate(Max('job'))
>>         ID = Id['job__max']
>>         job = Report.objects.filter(job = ID)
>>
>>         client =
>> Job.objects.all().filter(client=job).values('client__client__first_name',
>>         'client__client__middle_name', 'client__client__last_name',
>>         'client__client__address', 'client__client__city', 'date',
>> 'letter_no', 'letter_date')
>>
>>         temp = {'client':client, 'cubee':cubee, 'Head':Head,
>> 'organisation':organisation,'department':department,}
>>         return render_to_response('report/cube.html',
>> dict(temp.items() + tmp.items()),
>>         context_instance=RequestContext(request))
>>
>>
>> Error during template rendering
>>
>> In template /home/satinder/Automation/templates/report/header.html,
>> error at line 12
>>
>> 2 {% load i18n %}
>> 3 <html>
>> 4 {% block content %}
>> 5 <body>
>> 6 {% for Heads in Head %}
>> 7 <table width="100%"><tr>
>> 8 <td align="left"><a>No.GNDEC/TCC/R/{{Heads.job_id}}</td><td
>> align="right"><a>Dated{{Heads.dispatch_report_date}}</a></td>
>> 9 </tr></table>
>> 10 <!-- <p><b>Job no:</b><a style="padding-left:30px;
>> position:absolute">{{Heads.job_no}}</a></p>
>> 11 --> <p>To,</p>
>> 12 {% for add in client %}
>> 13 <p> {{ add.client__client__first_name}} {{
>> add.client__client__middle_name}}
>> {{add.client__client__last_name}}</p>
>> 14 <p> {{add.client__client__address}}</p>
>> 15 <p>{{ add.client__client__city}}</p>
>> 16 {% endfor %}
>> 17
>>
>> Can anybody help me to solve this error.
>>
>>
>> --
>> Satinderpal Singh
>> http://devplace.in/~satinder/wordpress/
>> http://satindergoraya.blogspot.in/
>> http://satindergoraya91.blogspot.in/
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Satinderpal Singh
http://devplace.in/~satinder/wordpress/
http://satindergoraya.blogspot.in/
http://satindergoraya91.blogspot.in/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to