1

I'm returning the following error when chaining together querys.

'itertools.chain' object has no attribute 'filter'

Here is my url page:

Entry_list = Entry.objects.all()
Category_list = Category.objects.all()

urlpatterns = patterns('django.views.generic.dates',
    url(r'^$',
        ArchiveIndexView.as_view(queryset= chain(Entry_list, Category_list),
                                 date_field='pub_date'),
                                 name='coltrane_entry_archive_index'),
)

It looks like this is due to the generic view.

python2.7/site-packages/django/views/generic/dates.py in get_dated_queryset, line 351

Is there another way to return both querysets to the template that would work with generic views?

byrdr
  • 5,197
  • 12
  • 48
  • 78
  • 1
    No, you'll need to make your own view that can accept multiple querysets – Anentropic Jan 13 '15 at 19:49
  • note also that when you do `Entry_list = Entry.objects.all()`... `Entry_list` isn't a list here, it's a `QuerySet` – Anentropic Jan 13 '15 at 19:50
  • You could also implement your own QuerySetChain that supports filter and order_by. See http://stackoverflow.com/a/432666/2193958 However, I think it's more trouble that it's worth. – Scintillo Jan 13 '15 at 20:12
  • It's also worth noting that I think you may have some problems with your database models if you need to do this. Maybe Entry and Category should have a "superclass" and contain foreign keys to this "superclass"? – Scintillo Jan 13 '15 at 20:16

0 Answers0