我想在保存表单时创建同一字段的多个对象。
例如:
我有一个模型名称“退休金”和另外两个模型“ Payrise and Bonus” 链接到带有外键的退休金模型。 因此,当我保存退休金创建表格时,我也想保存多个值以用于薪金和奖金模型。
def PensionCreateView(request):
if request.method == 'POST':
pension=Pension()
pension.pension_provider= request.POST.get('pension_provider')
pension.pension_scheme_id= request.POST.get('pension_scheme_id')
pension.pension_scheme_name= request.POST.get('pension_scheme_name')
pension.scheme= request.POST.get('scheme')
pension.salary_sacrifies= request.POST.get('salary_sacrifies')
pension.payrise_type= request.POST.get('payrise_type')
pension.bonus_type= request.POST.get('bonus_type')
pension.contribution_type= request.POST.get('contribution_type')
contribution = pension.contribution_type
pension.contribution_rates= request.POST.get('contribution_rates')
pension.save()
payrise = Payrise()
payrise.payrise_month = request.POST.getlist('payrise_month[]')