I wanted to know the difference between get_context_data and get_queryset.
And I'd like to hear from you about my codes.
What is right and what is wrong with them?
class SaleDetailView(DetailView):
template_name = 'vendas/sale/sale_detail.html'
model = Sale
def get_context_data(self, **kwargs):
s = Sale.objects.get(pk=self.kwargs['pk'])
sd = SaleDetail.objects.all().filter(sale=s)
context = super(SaleDetailView, self).get_context_data(**kwargs)
context['count'] = sd.count()
context['Sale'] = s
context['Itens'] = sd
return context
def get_queryset(self):
p = Product.objects.all()
q = self.request.GET.get('search_box')
# buscar por produto
if q is not None:
p = p.filter(product__icontains=q)
# filtra produtos em baixo estoque
if self.request.GET.get('filter_link', False):
p = p.filter(stock__lt=F('stock_min'))
return p
What can be improved on these codes?