Решение
class OrderCreateForm(forms.ModelForm):
class Meta:
model = Order
fields = [ 'email', 'postal_code', 'city', 'street',]
widgets = {
'email': forms.EmailInput(attrs={"class": "form-control", "placeholder": "e-mail"}),
'postal_code': forms.TextInput(attrs={"class": "form-control", "placeholder": "Почтовый индекс"}),
'city': forms.TextInput(attrs={"class": "form-control", "placeholder": "Город"}),
'street': forms.TextInput(attrs={"class": "form-control", "placeholder": "Улица"}),
}
def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrderCreateForm(request.POST)
if form.is_valid():
order = form.save(commit=False)
order.nickname = request.user
order.save()
for item in cart:
OrderItem.objects.create(order=order,
product=item['product'],
price=item['price'],
quantity=item['quantity'])
# очистка корзины
cart.clear()
return render(request, 'orders/order/created.html',
{'order': order})
else:
form = OrderCreateForm
return render(request, 'orders/order/create.html',
{'cart': cart, 'form': form})