django: auto generate list view with search (admin style) -


The easiest way to generate a list view for models with clickable headers and search (filter) fields- or Like without admin site? I read something about general thoughts, but I do not see a simple solution there.

General considerations are right for creating such functionality Table sorting, search and endorsement, client-side But using javascript plugins and later can be done.

To accomplish this, you need to define a general view and include it in the django.views.generic import list from urls.py:

  exampleapp .models Import BlogPost Category BlogPostListView (ListView): "" category that provides general list view "" "template_name =" list.html "def get_queryset (self): Back to BlogPost.objects.filter (published = true) urlpatterns = Pattern ('', '^ List / $', blog.postListView.as_view ()),)  

Everything else is done in the template file. The code below displays a table with 3 columns and initializes the Datatiles plugin, the pagination button and the search input will be added and the header cell will be clickable to sort according to the given column.

  & lt; Script type = "text / javascript" language = "javascript" src = "http://datatables.net/release-datatables/media/js/jquery.js"></script> & Lt; Script type = "text / javascript" language = "javascript" src = "http: // datalet .net / release-datatables / medie a / js / jquery.dataTables.js" & gt; & Lt; / Script & gt; & Lt; Script & gt; Validate the data structure on the & lt; table & gt; tag with $ (document) .ready (function () {// id = "example" $ ('# example')) .dataTable ();}); & Lt; / Script & gt; & Lt; Table id = "example" & gt; & Lt; Thead & gt; & Lt ;! - Header Row - & gt; & Lt; TR & gt; & Lt; TD & gt; Id & lt; / TD & gt; & Lt; TD & gt; Column 1 & lt; / TD & gt; & Lt; TD & gt; Column 2 & lt; / TD & gt; & Lt; / TR & gt; & Lt; / Thead & gt; & Lt; Tbody & gt; & Lt ;! - Data - & gt; %} For items in {Object_list.all%} & lt; Tr & gt; & Lt; Td> {{Item.id}} & lt; / Td> & Lt; Td> {{Item.column1}} & lt; / Td> & Lt; Td> {{Item.column2}} & lt; / Td> & Lt; / TR & gt; {% Endfor%} & lt; / Tbody & gt; & Lt; / Table & gt;  

Comments