Невозможно удалить объект: HViews выглядит следующим образом
def deleteorder(request, pk):
order = Order.object.get(id=pk)
if request.method == 'POST':
order.delete()
return redirect()
context = {'item':order}
return render(request,'accounts/delet.html', context)
И
Urls.py имеет вид
path('delete_order/<str:pk>/', views.deleteorder, name= 'delete_order')
models.py
class Order(models.Model):
STATUS = ( (' Pending', 'Pending'), ('Out for Delivery ', 'Out for Delivery '), ('Delivered ', 'Delivered ') , )
customers = models.ForeignKey(Customer, null=True, on_delete= models.SET_NULL)
products = models.ForeignKey( Product, null=True, on_delete = models.SET_NULL)
created_date = models.DateTimeField(auto_now_add=True, null=True)
status = models.CharField(max_length=100, null=True, choices = STATUS)
def __str__(self):
return self.products.name