python - Django Class model access self -


i'm using django package checks whether browser mobile. want apply paginate_by on mobile device there's less galleries using self.request.mobile. here's class:

class gallerylist(listview):     model = gallery     paginate_by = 20     context_object_name = 'galleries'     category = none      def get_queryset(self):         if self.request.mobile:             self.template_name = 'mobile/gallery.html'         qs = gallery.objects.filter(visible=true,).order_by('-created','-hot')         return qs 

you can override method get_template_names of listview following:

def get_template_names(self):     if self.request.mobile:         return 'mobile/gallery.html'     return 'normal/gallery.html' 

edit:

for paginate can try this:

def get_paginate_by(self, queryset):     if self.request.mobile:         return 5     return 20 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -