[Django] Any generalised or optimized way of handling multiple class based generic listviews in django ?

2019-10-06 Thread Dilipkumar Noone
Dear Django Users,

I am beginner in Django .

I have multiple generic list views in my django application where each list 
is handled under different navigation item of navigation bar .

Still i need to handle few more list views using class based generic view.

Is there any way to generalize or optimize in handling classbased 
genericlistview which reduces the code size when we need to handle multiple
lists in django application under each navigation item of navbar.?

*Note*: Each navigation item(webpage) has a list  & above the list we have 
a search form with filter button to search for a particular value.
  Each list view handles get_query_set and get_context_data .  

  *get_query_set *displays to retrieve the list of objects for a 
specific filter in a model when GET request occurs.

  *get_context_data* used to display the list of  objects and 
checks if request is GET and requested for a page in a list of pages listed 
using pagination.
  If key is a page continues the loop and it returns the context 
with the list of objects for the requested page as a key.



==
List1:

class GSPDCList(ListView):


List2:

class GSPECList(ListView):

List3:
 =:

List4:
 (ListView):

*This concept i need to apply in my django app with multiple class based 
generic views where each listview specific to diff model and filter 
options.*

*So please suggest and optimized way of handling this requirement 
to reduce the code size.*


Regards,
N.Dilip Kumar.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7cdeceec-7720-44fb-833f-f30db7c00a12%40googlegroups.com.


Re: [Django] Any generalised or optimized way of handling multiple class based generic listviews in django ?

2019-10-07 Thread Pradeep Sukhwani


Hi Dilip,
A few days back I stuck at the same issue, then I tried with the queryset 
union functionality:


class MultiFilterPlacesListView(ListAPIView):
 """Custom queryset api view. Does not implement pagination"""

 pagination_class = None # Import custom pagination if you need the 
pagination.
 queryset = Places.objects.all()
 slice_size = 10  # count limit for each of the source queries

 def get_queryset(self):
 """Combine queries from new, editor choice and popular"""
 new_qs = self.queryset.filter(new_place=True)[:self.slice_size]
 editor_qs = self.queryset.filter(editor_choice=True)[:self.slice_size]
 popular_qs = self.queryset.filter(popular=True)[:self.slice_size]

 return new_qs.union(editor_qs, popular_qs, all=True) # Output will be 
union of the above two querysets


Doc: Django 

Example: StackOverflow 

Note:
if you are doing the union, then you won't get the pagination. In my case, 
I also needed pagination so I wrote custom pagination.


On Sunday, October 6, 2019 at 1:53:46 PM UTC+5:30, Dilipkumar Noone wrote:
>
> Dear Django Users,
>
> I am beginner in Django .
>
> I have multiple generic list views in my django application where each 
> list is handled under different navigation item of navigation bar .
>
> Still i need to handle few more list views using class based generic view.
>
> Is there any way to generalize or optimize in handling classbased 
> genericlistview which reduces the code size when we need to handle multiple
> lists in django application under each navigation item of navbar.?
>
> *Note*: Each navigation item(webpage) has a list  & above the list we 
> have a search form with filter button to search for a particular value.
>   Each list view handles get_query_set and get_context_data .  
> 
>   *get_query_set *displays to retrieve the list of objects for a 
> specific filter in a model when GET request occurs.
>
>   *get_context_data* used to display the list of  objects and 
> checks if request is GET and requested for a page in a list of pages listed 
> using pagination.
>   If key is a page continues the loop and it returns the context 
> with the list of objects for the requested page as a key.
>
> 
>
>
> ==
> List1:
>
> class GSPDCList(ListView):
>
>
> List2:
>
> class GSPECList(ListView):
>
> List3:
>  =:
>
> List4:
>  (ListView):
>
> *This concept i need to apply in my django app with multiple class based 
> generic views where each listview specific to diff model and filter 
> options.*
>
> *So please suggest and optimized way of handling this requirement 
> to reduce the code size.*
>
>
> Regards,
> N.Dilip Kumar.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/21a32925-9fac-4c57-a03a-0aabf0d97642%40googlegroups.com.


Re: [Django] Any generalised or optimized way of handling multiple class based generic listviews in django ?

2019-10-07 Thread Dilipkumar Noone
Dear Pradep Sukhwani,

The Below QuerySetUnion functionality will work if you have multiple 
querysets from one model as per my understanding.

How to proceed if i have different number of querysets from multiple models.
 [ say 5 models in my django project ,each has one queryset and context 
data.  ]

This case how to proceed ?
 

Regards,
N.Dilip Kumar.

On Sunday, October 6, 2019 at 1:53:46 PM UTC+5:30, Dilipkumar Noone wrote:
>
> Dear Django Users,
>
> I am beginner in Django .
>
> I have multiple generic list views in my django application where each 
> list is handled under different navigation item of navigation bar .
>
> Still i need to handle few more list views using class based generic view.
>
> Is there any way to generalize or optimize in handling classbased 
> genericlistview which reduces the code size when we need to handle multiple
> lists in django application under each navigation item of navbar.?
>
> *Note*: Each navigation item(webpage) has a list  & above the list we 
> have a search form with filter button to search for a particular value.
>   Each list view handles get_query_set and get_context_data .  
> 
>   *get_query_set *displays to retrieve the list of objects for a 
> specific filter in a model when GET request occurs.
>
>   *get_context_data* used to display the list of  objects and 
> checks if request is GET and requested for a page in a list of pages listed 
> using pagination.
>   If key is a page continues the loop and it returns the context 
> with the list of objects for the requested page as a key.
>
> 
>
>
> ==
> List1:
>
> class GSPDCList(ListView):
>
>
> List2:
>
> class GSPECList(ListView):
>
> List3:
>  =:
>
> List4:
>  (ListView):
>
> *This concept i need to apply in my django app with multiple class based 
> generic views where each listview specific to diff model and filter 
> options.*
>
> *So please suggest and optimized way of handling this requirement 
> to reduce the code size.*
>
>
> Regards,
> N.Dilip Kumar.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0793db4b-7d31-4956-b573-385c09f74234%40googlegroups.com.