Re: Query set append

2014-12-02 Thread check . django
Thanks guys . Appreciate the help !!

On Monday, December 1, 2014 11:07:59 AM UTC-8, check@gmail.com wrote:
>
> Hello 
>
> I am very new to python and Django . I have a basic question :
>
> 1. I have three database tables : Table A , Table B and Table C
> 2. in my views.py i do :
>
>- tableB_QuerySet = models.TableB.objects.filter(table_ID = value>)
>- *This returns 4 rows from table B *
>- Then i iterate over tableB_QuerySet 
>
> for x in tableB_QuerySet
> tableC_QuerySet = 
> models.TableC.objects.filter(tableC_id = x.)
>
>- I load the temple : template = loader.get_template(>.html>)
>- i use context : context  = RequestContext(request,{ '
>tableC_QuerySet': tableC_QuerySet,})
>- return HttpResponse(template.render(context))
>
> 3. In my html template i iterate over tableC_QuerySet and print it in a 
> table 
>
>
> problem is that in my HTML prints only the last entry of  tableC_QuerySet 
> . How do i append all the four entries from table C so that HTML gets all 
> the four entries rather than just the last one 
>
> PS: I cannot change the DB
>
> Thanks in advance 
> Appreciate your help
>
>
>
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d30203df-4a3e-468a-b417-4a3feae6af5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Query set append

2014-12-02 Thread Florian Schweikert

On 2014-12-01 20:07, check.dja...@gmail.com wrote:

* I load the temple : template = loader.get_template(>.html>)
* i use context : context = RequestContext(request,{
'tableC_QuerySet': tableC_QuerySet,})
* return HttpResponse(template.render(context))


you may also have a look at the render shortcut:
https://docs.djangoproject.com/en/1.7/topics/http/shortcuts/#render

-- Florian

--
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cb1971d3ad75fb9e265532b1a72e4237%40ist-total.org.
For more options, visit https://groups.google.com/d/optout.


Re: Query set append

2014-12-02 Thread Daniel Roseman
On Monday, 1 December 2014 19:07:59 UTC, check@gmail.com wrote:
>
> Hello 
>
> I am very new to python and Django . I have a basic question :
>
> 1. I have three database tables : Table A , Table B and Table C
> 2. in my views.py i do :
>
>- tableB_QuerySet = models.TableB.objects.filter(table_ID = value>)
>- *This returns 4 rows from table B *
>- Then i iterate over tableB_QuerySet 
>
> for x in tableB_QuerySet
> tableC_QuerySet = 
> models.TableC.objects.filter(tableC_id = x.)
>
>- I load the temple : template = loader.get_template(>.html>)
>- i use context : context  = RequestContext(request,{ '
>tableC_QuerySet': tableC_QuerySet,})
>- return HttpResponse(template.render(context))
>
> 3. In my html template i iterate over tableC_QuerySet and print it in a 
> table 
>
>
> problem is that in my HTML prints only the last entry of  tableC_QuerySet 
> . How do i append all the four entries from table C so that HTML gets all 
> the four entries rather than just the last one 
>
> PS: I cannot change the DB
>
> Thanks in advance 
> Appreciate your help
>
>
Well, this is a basic programming issue, and nothing to do with Python or 
Django.

Each time through your loop, you re-assign `tableC_QuerySet` to a new 
value. So, naturally, the value that it has at the end of the loop is 
whatever it had in the last iteration. If you want to get all the elements 
from each iteration, you'll need to put them into a list. For example:

values = []
for x in tableB_QuerySet:
values.extend(list(models.TableC.objects.filter(tableC_id = 
x.)))

In addition, there is almost certainly a more efficient way to do it, 
rather than doing a separate query for each tableB item, but without seeing 
more details of your models it's impossible to help further.
--
DR.

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/44fcfb41-ab96-4cc4-a74c-9ae0b6d7c4c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Query set append

2014-12-01 Thread Simon Charette
Try using a subquery for this:

tableC_QuerySet = models.TableC.objects.filter(
tableC_id__in=models.TableB.objects.filter(table_ID = ).values()
)

Le lundi 1 décembre 2014 14:07:59 UTC-5, check@gmail.com a écrit :
>
> Hello 
>
> I am very new to python and Django . I have a basic question :
>
> 1. I have three database tables : Table A , Table B and Table C
> 2. in my views.py i do :
>
>- tableB_QuerySet = models.TableB.objects.filter(table_ID = value>)
>- *This returns 4 rows from table B *
>- Then i iterate over tableB_QuerySet 
>
> for x in tableB_QuerySet
> tableC_QuerySet = 
> models.TableC.objects.filter(tableC_id = x.)
>
>- I load the temple : template = loader.get_template(>.html>)
>- i use context : context  = RequestContext(request,{ '
>tableC_QuerySet': tableC_QuerySet,})
>- return HttpResponse(template.render(context))
>
> 3. In my html template i iterate over tableC_QuerySet and print it in a 
> table 
>
>
> problem is that in my HTML prints only the last entry of  tableC_QuerySet 
> . How do i append all the four entries from table C so that HTML gets all 
> the four entries rather than just the last one 
>
> PS: I cannot change the DB
>
> Thanks in advance 
> Appreciate your help
>
>
>
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e0a1fc01-e8a2-49d3-a087-4614f0086fcc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Query set append

2014-12-01 Thread check . django
Hello 

I am very new to python and Django . I have a basic question :

1. I have three database tables : Table A , Table B and Table C
2. in my views.py i do :

   - tableB_QuerySet = models.TableB.objects.filter(table_ID = )
   - *This returns 4 rows from table B *
   - Then i iterate over tableB_QuerySet 

for x in tableB_QuerySet
tableC_QuerySet = 
models.TableC.objects.filter(tableC_id = x.)

   - I load the temple : template = loader.get_template(>.html>)
   - i use context : context  = RequestContext(request,{ 'tableC_QuerySet': 
   tableC_QuerySet,})
   - return HttpResponse(template.render(context))

3. In my html template i iterate over tableC_QuerySet and print it in a 
table 


problem is that in my HTML prints only the last entry of  tableC_QuerySet . 
How do i append all the four entries from table C so that HTML gets all the 
four entries rather than just the last one 

PS: I cannot change the DB

Thanks in advance 
Appreciate your help



-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/196e21b6-91f4-4121-a807-fe432ef69508%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.