class Book(models.Model):
borrowed = models.BooleanField(default=False)
borrow_count = models.PositiveIntegerField(default=0)
答案 0 :(得分:0)
也许你应该在视图中这样做:
def book_borrow_status_change(request):
if request.method == "POST":
form = BorrowStatusChangeForm(request.POST)
if form.is_valid():
book_id = form.cleaned_data['book_id']
borrowed = form.cleaned_data['borrowed']
book = get_object_or_404(Book, pk=book_id)
book.borrowed = borrowed
book.borrow_count = book.borrow_count + 1
book.save()
else:
return HttpResponse("Form is not valid")
return HttpResponseRedirect(reverse_lazy('book'))