Thank You, Roland, this was a good point to start with. I now found an 
elegant solution:

I added a base DetailView class for this project:

from django.views.generic import DetailView

class PluggableDetailView(DetailView):
    def get_context_data(self, **kwargs):

        context = super(PluggableDetailView, 
self).get_context_data(**kwargs)
        for plugin in self.__class__.__bases__:
            if hasattr(plugin, 'get_extra_context') and
 callable(plugin.get_extra_context):
                context.update(plugin.get_extra_context(self, **kwargs))
        return context

    def post(self, *args, **kwargs):
        for plugin in self.__class__.__bases__:
            if hasattr(plugin, 'handle_post_request') and
 callable(plugin.handle_post_request):
                plugin.handle_post_request(self, *args, **kwargs)

now I can add plug-ins and add two methods 

get_extra_context shall return a dict of extra context data merged together 
with the default context.

handle_post_request shall extract the plug-in specific post data and update 
the database or whatever else it must do.

The DetailView of the main app then inherits from PluggableDetailView, 
additional plug-ins can be mixed in, but no extra code has to be written to 
extend the context or to handle post requests.

class MainAppDetailView(PluggableDetailView, PluginAMixin, PluginBMixin):
    pass
Does this approach make sense or did I reinvent the wheel?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/r_ZDUciOi6IJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to