def get(self, request, *args, **kwargs): return self.render_to_response(context = { 'models': { model_name: models.get_finance_class(model_name) for model_name in finance_categories } })
def get(self, request, *args, **kwargs): model_class = models.get_finance_class(self.kwargs['category']) finance_object = get_object_or_404(model_class, pk = int(self.kwargs['pk'])) context = self._get_context() context.update({ 'finance_object': finance_object, }) return self.render_to_response(context = context)
def _get_context(self): category = self.kwargs['category'] model = models.get_finance_class(category) return { 'category': category, 'model': model, 'need_log': model.need_log }
def create_viewset(model_name): model_class = models.get_finance_class(model_name) log_model_class = models.get_log_class(model_name) class FinanceAPIViewSet(viewsets.ReadOnlyModelViewSet, ListCacheMixin): model = model_class serializer_class = serializers.get_serializer_class(model_class) class FinanceLogAPIViewSet(viewsets.ReadOnlyModelViewSet, ListCacheMixin): model = log_model_class serializer_class = serializers.get_log_serializer_class(log_model_class) def get_queryset(self): pk = int(self.kwargs['finance_pk']) return log_model_class.objects.filter(finance_object = pk) return (FinanceAPIViewSet, FinanceLogAPIViewSet)