[Answer]-Django: How to set up a single view for multiple urls where each url points to subclass of a base model?

1👍

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
…

The proper way of solving this is passing an extra option to the view. See related documentation entry.

Example:

url('^college/$', 'tag_view', {'model': College})

def tag_view(request, model):
    records = model.objects.filter(…)

Furthermore, actions should not be included in URL’s name. URLs should identify resources. Therefore I would skip the browse part of the URL.

Leave a comment