django ListView specifying variable available for all methods inside the class
问题 My url has a keyword "shop_name" variable. There's also the Shop model with "name" field. In my ListView class I need to make repeating queries to Shop model to get a unicode variable from Shop.get_type() method. Depending on the result, a proper template directory is selected or queryset (Using subclassed django models). Here's the code. class OfferList(ListView): def get_template_names(self): shop = Shop.objects.get(name=self.kwargs['shop_name']) return ["shop/%s/offer_list" % shop.get_type