Hi, I’m new with django.
I am trying to create a view that shows a list all objects of a model. Furthermore, I want that shows some attributes and enables ordering on click.
In short, I wish to build a view (page) like de admin page:
There’s a easy away to “copy” this page/view ?
Thanks
You mention that you are “Hi, I’m new with django.”
How new?
For example, have you worked through either or both of the Official Django Tutorial or the Django Girls tutorial?
Have you already worked on one or more other projects?
Have you worked with the generic Class Based Views? (If so, see the ListView as a starting point.)
You can also look at the source code for the admin page to see how it builds those lists.
The view is changelist_view in django.contrib.admin.options. (Admittedly, that part of the code might be a bit “dense”, since it’s doing a lot of things that you aren’t looking to do. For example, if you’re just looking at producing the list, you can ignore all the parts of that view handling a POST.)
The template being used to render the list is change_list_results.html, located in django.contrib.admin.templates.admin.
You can look at the page that was rendered to see how the “sort” option is handled within the html. (Also notice what happens to the url when you select a column to sort.)
Blockquote have you worked through either or both of the Official Django Tutorial or the Django Girls tutorial?
I have been worked through the Official Django Tutorial and the Mozilla Django Web Framework
But now I’m trying some think new.
Thanks for the reply. I am going to see the generic Class Based Views and the admin templates.