Using a paginator with two models in the same view

45 views
Skip to first unread message

Some Developer

unread,
Feb 7, 2014, 11:46:54 AM2/7/14
to django...@googlegroups.com
I have two models: Thread and EmailThread. As the names suggest the
Thread model relates to threads created via the web interface and the
EmailThread model relates to threads created via email.

I want to display a list of all threads from both models on the same
page and I want to paginate this page. If there was only a single model
to paginate the page by then it would be easy but I'm having difficulty
finding a way to paginate a page that has two models listed on the same
page.

Can anyone suggest an option? I guess I could split them so that each
model had its own listing view but that seems a bit messy to me. It
would be much nicer if they were held on the same page.

Thanks for any help.

C. Kirby

unread,
Feb 11, 2014, 12:52:40 PM2/11/14
to django...@googlegroups.com
Paginator will work on any list/tuple of objects, not just querysets. If you have a way to transform your 2 querysets into a single list you can use that as your pagination object.
Not knowing enough about your architecture I can't really discuss how you might go about the transformation step.

Some Developer

unread,
Feb 11, 2014, 8:14:18 PM2/11/14
to django...@googlegroups.com
Ah, I didn't realise that.

I think I should be able to do the transformation pretty easily. Thanks for the info that has sorted out a rather irrating problem I have been having. I'll give that a try tomorrow when I have some free time.
--
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...@googlegroups.com.
To post to this group, send email to django...@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/da0342f4-c89d-4d38-8c00-a3a91539cf3c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Fabio Caritas Barrionuevo da Luz

unread,
Feb 12, 2014, 8:19:47 AM2/12/14
to django...@googlegroups.com
Please, if you can solve, create a post on a blog or a gist.github.com to resolution, and send to this topic. 
This can be useful for other people. XD
Reply all
Reply to author
Forward
0 new messages