它正在工作,今天我有这个错误,为什么?
get_context_data中的/root/.local/share/virtualenvs/pp-lX8UY0eG/lib/python3.7/site-packages/django/views/generic/list.py,行115 AttributeError:'OrderCreateView'对象没有属性'object_list'
views.py
class OrderCreateView(LoginRequiredMixin, CustomSuccessMessageMixin, CreateView, ListView):
model = Order
template_name = 'index.html'
form_class = OrderForm
success_url = reverse_lazy('orders')
success_msg = 'Заказ сохранён'
# this method will pass 'user' as param in kwargs to form __init__()
def get_form_kwargs(self):
kwargs = super(OrdersInfoView, self).get_form_kwargs()
kwargs['user'] = self.request.user
return kwargs
def get_context_data(self, **kwargs):
kwargs['list_orders'] = Order.objects.all().order_by('-id')
kwargs['customer_form'] = CustomerOrderForm
return super().get_context_data(**kwargs)
def form_valid(self, form):
self.object = form.save(commit=False)
self.object.author = self.request.user
new_number = self.object.author.order_set.count() + 1
self.object.number_order = str(new_number)
self.object.save()
return super().form_valid(form)