Django - Generic Views - Object_list - What's the benefit?
I want to use the object_list generic view. But I can't tell what benefit it gives me besides pagination? It seems like I still need to write my own template?
How 开发者_如何学运维is this faster than writing my own view? Am I missing something?
If it is worth using and I do have to write my own template, what is supposed to be in the template? I can't find any examples.
If you have more than one model, it saves you some time duplicating a similar view and template. Say you write an app with 15 models, you still only need 1 generic view and 1 template to show all of them.
You are right in thinking that the function-based generic views do not save you very much. As soon as you need just a little bit of customization you end up writing the view yourself. You should also note that they deprecated in Django 1.3 and there is a migration guide.
On the other hand the new class-based generic views in 1.3 are very handy. You can write the same list view logic and swap out a response mix-in to render an Excel spreadsheet or return JSON instead of rendering a template.
精彩评论