Re: Paginator and foreign key
On 13 déc, 19:49, refreegrata wrote: > thanks for the answer, but the solution don't show anything. I must be > doing something wrong. > if now I have > --- > class Myline(models.mode): > fk_myDoc = models.ForeignKey(MyDoc, related_name="") > --- > > How Can I use {% for line doc.X_set.all %} in the template? > I'm sorry for this asking, but I can't find the _set.all option in the > Django documentation. http://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects -- 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: Paginator and foreign key
thanks for the answer, but the solution don't show anything. I must be doing something wrong. if now I have --- class Myline(models.mode): fk_myDoc = models.ForeignKey(MyDoc, related_name="") --- How Can I use {% for line doc.X_set.all %} in the template? I'm sorry for this asking, but I can't find the _set.all option in the Django documentation. -- 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: Paginator and foreign key
On 13 déc, 16:59, refreegrata wrote: > Hello list, I have a question. Take a look to the next models. > > class MyDoc(models.Model): > code = models.BigIntegerField() > > class Myline(models.mode): > fk_myDoc = models.ForeignKey(MyDoc) > --- > > In my view I do something like > > myPaginator = Paginator(MyDoc.objects.filter(codigo=1), 10) > myDocs = myPaginator.page(page_number) > > This return all the Docs with a code=1, but I too want to return all > the objects with the type "MyLine" associated to the results of this > query. for doc in myDocs.object_list: print doc.MyLine_set.all() or in your template: {% for doc in myDocs.object_list %} {{ doc.code }} {% for line doc.MyLine_set.all %} {{ line }} {% endfor %} {% endfor %} -- 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: Paginator and foreign key
if I return another list: --- for i in range(len(paginatorDocs.object_list)): resultados = {'myDoc': paginatorDocs.object_list[i], 'myLines': Myline.objects.filter(fk_myDoc=paginatorDocs.object_list[i].id),} --- With this I can get the values, but I'm not sure if this is the best way to solve the problem -- 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.
Paginator and foreign key
Hello list, I have a question. Take a look to the next models. class MyDoc(models.Model): code = models.BigIntegerField() class Myline(models.mode): fk_myDoc = models.ForeignKey(MyDoc) --- In my view I do something like myPaginator = Paginator(MyDoc.objects.filter(codigo=1), 10) myDocs = myPaginator.page(page_number) This return all the Docs with a code=1, but I too want to return all the objects with the type "MyLine" associated to the results of this query. I try to do something like for i in range(len(myDocs.object_list)) myDocs.object_list[i].append(Myline.objects.filter(fk_myDoc=myDocs.object_list[i].id)) - but don't work I know that I can do 2 queries and return two list, one with the myDoc list and other with the myLine list, but in that case in my template I must to do something like {% for myDoc im MyDocs.object.list %} {% for myline in Mylines %} {%if myDoc.id == myline.fk_myDoc %} .. {% endif %} {% endfor %} {% endfor %} I don't want to do this, because I think a big "for" inside a big "for" is innecessary. Somebody have an idea?? Thanks for read, and sorry for my bad english. -- 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.