data must be QuerySet-like (have count() and order_by()) or support list(data) -- NoneType has neither

321 views
Skip to first unread message

Ali khan

unread,
Jan 7, 2017, 10:19:01 PM1/7/17
to django...@googlegroups.com
I am using Django-table2 for SingleTableMixin and I am getting this error which I am not able to come around. Error says I need to present data in query to be able to make it work. Following is the code and guidance is requested.

class ProductListView(SingleTableMixin, generic.TemplateView):
   
    template_name = 'dashboard/catalogue/product_list.html'
    form_class = ProductSearchForm
    productclass_form_class = ProductClassSelectForm
    table_class = ProductTable
    context_table_name = 'products'
    def get_context_data(self,**kwargs):
        ctx = super(ProductListView, self).get_context_data(**kwargs)
        ctx['form'] = self.form
        ctx['productclass_form'] = self.productclass_form_class()
        return ctx
    def get_description(self, form):
        if form.is_valid() and any(form.cleaned_data.values()):
            return _('Product search results')
        return _('Products')
    def get_table(self, **kwargs):
        if 'recently_edited' in self.request.GET:
            kwargs.update(dict(orderable=False))
        table = super(ProductListView, self).get_table(**kwargs)
        table.caption = self.get_description(self.form)
        return table
    def get_table_pagination(self):
        return dict(per_page=20)
    def filter_queryset(self, queryset):
       
        return filter_products(queryset, self.request.user)
    def get_queryset(self):
       
        queryset = Product.browsable.base_queryset()
        queryset = self.filter_queryset(queryset)
        queryset = self.apply_search(queryset)
        return queryset
Error I am getting is below:

Request Method: GET
Request URL: http://localhost:8000/dashboard/catalogue/
Django Version: 1.8.16
Python Version: 2.7.12
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.flatpages',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'phonenumber_field',
 'haystack',
 'default.templatetags',
 'treebeard',
 'sorl.thumbnail',
 'django_tables2',
 'compressor',
 'widget_tweaks',
 'catalogue',
 'catalogue.reviews',
 'customer',
 'customer.alerts',
 'customer.notifications',
 'customer.wishlists',
 'analytics',
 'partner',
 'offer',
 'order',
 'address',
 'basket',
 'voucher',
 'wishlist',
 'shipping',
 'promotions',
 'payment',
 'dashboard',
 'dashboard.catalogue',
 'dashboard.communications',
 'dashboard.orders',
 'dashboard.offers',
 'dashboard.pages',
 'dashboard.partners',
 'dashboard.promotions',
 'dashboard.ranges',
 'dashboard.reports',
 'dashboard.reviews',
 'dashboard.shipping',
 'dashboard.users',
 'dashboard.vouchers',
 'purl')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'basket.middleware.BasketMiddleware',
 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware')

Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python27\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
  22.                 return view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\generic\base.py" in view
  71.             return self.dispatch(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\generic\base.py" in dispatch
  89.         return handler(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\generic\base.py" in get
  158.         context = self.get_context_data(**kwargs)
File "C:\Users\AliKhan\supermarket\market\dashboard\catalogue\views.py" in get_context_data
  77.         ctx = super(ProductListView, self).get_context_data(**kwargs)
File "C:\Python27\lib\site-packages\django_tables2\views.py" in get_context_data
  107.         table = self.get_table(**self.get_table_kwargs())
File "C:\Users\AliKhan\supermarket\market\dashboard\catalogue\views.py" in get_table
  91.         table = super(ProductListView, self).get_table(**kwargs)
File "C:\Python27\lib\site-packages\django_tables2\views.py" in get_table
  82.         table = table_class(self.get_table_data(), **kwargs)
File "C:\Python27\lib\site-packages\django_tables2\tables.py" in __init__
  348.         self.data = self.TableDataClass(data=data, table=self)
File "C:\Python27\lib\site-packages\django_tables2\tables.py" in __init__
  45.             ' list(data) -- {} has neither'.format(type(data).__name__)
Exception Type: ValueError at /dashboard/catalogue/
Exception Value: data must be QuerySet-like (have count() and order_by()) or support list(data) -- NoneType has neither

Vijay Khemlani

unread,
Jan 8, 2017, 9:53:45 AM1/8/17
to django...@googlegroups.com
At least by looking at the source code

https://github.com/bradleyayers/django-tables2/blob/master/django_tables2/views.py

It seems you need to have a "table_data" attribute, or a "object_list"
attribute, or define a "get_table_data" method in your class
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAAXvsYkWokyBpF2rzGThJeKFN2%3DZR2ezM0rSbDXnjyQr0tu_ug%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>

Ali khan

unread,
Jan 11, 2017, 1:44:36 AM1/11/17
to django...@googlegroups.com
Vijay,

I've tried many ways but its not working.
Can you show me an example the way you proposed.
Its also surprising for me that in Django Users group so little people contribute to solving issues.

Thanks Vijay for your response at the first place.

Regards,
Ali

--
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+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Vijay Khemlani

unread,
Jan 11, 2017, 7:31:09 AM1/11/17
to django...@googlegroups.com
Maybe because this is a list for django, not particular django libraries.

Did you look at the source code? Did you implement the get_table_data() method? 

Reply all
Reply to author
Forward
0 new messages