I am wondering how to run a reality check to decide which template file to use. How do I access agency_count from AgencyFullView? What I currently have returns type object 'AgencyFullMixin' has no attribute 'agency_count'
class AgencyFullMixin(ContextMixin):
def get_context_data(self, pk, **kwargs):
context_data = super(AgencyFullMixin, self).get_context_data(**kwargs)
agency = Agencies.objects.filter(pk=pk)
context_data["agency"] = agency
agency_count = agency.count()
context_data["agency_count"] = agency_count
return context_data
class AgencyFullView(TemplateView, AgencyFullMixin):
if agency_count != 0: **<<<--- What to put here?**
template_name = 'community_information_database/agency_full.html'
else:
template_name = 'community_information_database/not_valid.html'
def get_context_data(self, **kwargs):
context_data = super(AgencyFullView, self).get_context_data(**kwargs)
return context_data
agency_countvariable in the mixin class either, you haveagency_count_test. Mind you thatagency_count_testis a local variable and it will go away once the get_context_data() method returns.if agency_count != 0code will only run once at the application start, not for every request and so cannot use this count.returnoutside of a method.