18.3 Globally Setting Template Suffix for Update Views

In TagUpdate, StartupUpdate, and NewsLinkUpdate, we have set the template_name_suffix attributes to be exactly the same value (and we follow suit with PostUpdate in this chapter).

Setting duplicate attributes to use the same resource violates DRY (Don’t Repeat Yourself) principles and is very easy to avoid. In a new file, core/utils.py, we can create our own UpdateView GCBV, using Django’s own UpdateView GCBV as a base, as shown in Example 18.3.

Example 18.3: Project Code

core/utils.py in 2825fb7c70

1   from django.views.generic import \ 2       UpdateView as BaseUpdateView 3 4 5   class UpdateView(BaseUpdateView): 6       template_name_suffix = '_form_update' ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.