Last week I’ve migrated a Django application from version 1.04 to 1.6.
Among the many methods deprecated, starting from version 1.5 all generic views based on functions have been eliminated (they were already deprecated in the previous release (https://docs.djangoproject.com/en/1.4/topics/generic-views-migration/)
In my application, the generic view was used in the views.py file in this way:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | @cache_page() |
As we can see, our method in the view creates a generic list of comments, further adding an extra_context.
During the migration to version 1.6 of Django, I had to face two problems:
- To migrate from function-based generic views to class-based analogs
- The impossibility to add an extra_context in the new ListView class.
First of all, I’ve extended the ListView class this way (in order to add an extra_context parameter):
1 2 3 4 5 6 7 8 | from django.views.generic import ListView |
Then, I’ve changed the view as follow:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | @cache_page(CACHE_MIDDLEWARE_SECONDS) |
What do you think of this solution?