from django.shortcuts import render, get_object_or_404 from django.urls import reverse from django.views.generic.edit import CreateView from django.views.generic.base import TemplateView from django.views.generic.list import ListView from django.views.generic.detail import DetailView from .models import * class ProductOrderView(CreateView): model = ProductOrder fields = ['resources'] def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['product'] = get_object_or_404(Product, slug=self.kwargs['product']) context['timeframe'] = get_object_or_404(TimeFrame, slug=self.kwargs['timeframe']) print(context) print(self.kwargs) return context class ProductDetailView(DetailView): model = Product def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['productorder'] = reverse('product-order', kwargs={'product': self.object.slug }) context['timeframes'] = context['product'].valid_timeframes() print(context) return context class ProductListView(ListView): model = Product class ProductSelectView(CreateView): model = ProductOrder fields = ['product' ] class Yearly(TemplateView): template_name = "app/config_product.html" def get_context_data(self, **kwargs): context = super(Yearly, self).get_context_data(**kwargs) context['current_year'] = self.current_year context['current_month'] = self.current_month return context