本文整理汇总了Python中forms.ItemForm.hide_field方法的典型用法代码示例。如果您正苦于以下问题:Python ItemForm.hide_field方法的具体用法?Python ItemForm.hide_field怎么用?Python ItemForm.hide_field使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.ItemForm
的用法示例。
在下文中一共展示了ItemForm.hide_field方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_item
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import hide_field [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,
})