本文整理匯總了Python中models.Transaction.new方法的典型用法代碼示例。如果您正苦於以下問題:Python Transaction.new方法的具體用法?Python Transaction.new怎麽用?Python Transaction.new使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Transaction
的用法示例。
在下文中一共展示了Transaction.new方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: save_outgoing
# 需要導入模塊: from models import Transaction [as 別名]
# 或者: from models.Transaction import new [as 別名]
def save_outgoing(request):
error = False
transaction = Transaction.new()
transaction.user_id = request.POST.get('user')
transaction.borrow_date = request.POST.get('borrow_date')
transaction.due_date = request.POST.get('due_date')
transaction.record_id = request.POST.get('record')
if request.POST.get('isbn'):
isbn = request.POST.get('isbn')
if isbnpy.isValid(isbn):
if isbnpy.isI10(isbn):
isbn = isbnpy.convert(isbn)
try:
transaction.record = Record.objects.get(isbn13=isbn)
except Record.DoesNotExist:
error = 'No books with provided ISBN in library database.'
else:
error = 'Invalid ISBN!'
if error:
raise Exception(error)
transaction.save()
messages.success(request, 'Checked Out!')
return redirect(reverse_lazy('view_record', kwargs={'pk': transaction.record_id}))
示例2: outgoing
# 需要導入模塊: from models import Transaction [as 別名]
# 或者: from models.Transaction import new [as 別名]
def outgoing(request, pk=None):
transaction = Transaction.new()
if pk:
transaction.record = Record.objects.get(id=pk)
form = OutgoingForm(instance=transaction)
return render(request, 'outgoing.html', {'form': form})