本文整理汇总了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})