本文整理汇总了Python中models.Item.company方法的典型用法代码示例。如果您正苦于以下问题:Python Item.company方法的具体用法?Python Item.company怎么用?Python Item.company使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Item
的用法示例。
在下文中一共展示了Item.company方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_item
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import company [as 别名]
def create_item(request):
"""
@param request:
@param id:
@return: JSON for account for added Inventory Item
"""
item = Item(purchase_account=Account.objects.get(name='Purchase', company=request.company),
sales_account=Account.objects.get(name='Sales', company=request.company),
purchase_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company),
sales_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company))
scenario = 'Create'
for query in request.GET:
setattr(item, query, request.GET[query])
if request.POST:
form = ItemForm(data=request.POST, instance=item, company=request.company)
if form.is_valid():
item = form.save(commit=False)
item.company = request.company
item.save()
if request.is_ajax():
return render(request, 'callback.html', {'obj': InventoryAccountSerializer(item.account).data})
return redirect('/inventory/items/')
else:
form = ItemForm(instance=item, company=request.company)
form.hide_field(request)
if request.is_ajax():
base_template = 'modal.html'
else:
base_template = 'dashboard.html'
return render(request, 'item_form.html', {
'scenario': scenario,
'form': form,
'base_template': base_template,
})
示例2: item_form
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import company [as 别名]
def item_form(request, id=None):
if id:
item = get_object_or_404(Item, id=id, company=request.company)
scenario = 'Update'
else:
item = Item(purchase_account=Account.objects.get(name='Purchase', company=request.company),
sales_account=Account.objects.get(name='Sales', company=request.company),
purchase_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company),
sales_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company))
scenario = 'Create'
if request.POST:
form = ItemForm(data=request.POST, instance=item, company=request.company)
if form.is_valid():
item = form.save(commit=False)
item.company = request.company
item.save()
if request.is_ajax():
return render(request, 'callback.html', {'obj': ItemSerializer(item).data})
return redirect('/inventory/items/')
else:
form = ItemForm(instance=item, company=request.company)
if request.is_ajax():
base_template = 'modal.html'
else:
base_template = 'dashboard.html'
return render(request, 'item_form.html', {
'scenario': scenario,
'form': form,
'base_template': base_template,
})