On 13 déc, 16:59, refreegrata <refreegr...@yahoo.com> 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:

<ul>
{% for doc in myDocs.object_list %}
  <li>
     {{ doc.code }}
     <ul>
       {% for line doc.MyLine_set.all %}
       <li>{{ line }}</li>
       {% endfor %}
     </ul>
   </li>
{% endfor %}
</ul>

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