说明:模板完美呈现自动完成......但是一旦我对其进行测试并单击“添加管理器”,它就会返回此错误:
Exception Type: IntegrityError
Exception Value: investments_managesfund.manager_id may not be NULL
我想不通。因为在 POST 中,它发送的是 csrf_token 和 manager 用户名。
添加经理以资助 VIEWs.py:
@login_required
def add_manager_to_fund(request, fund_id):
fund = get_object_or_404(Fund, id=fund_id)
if request.POST['from'] == 'fund':
if 'omnibox' in request.POST:
manager = ManagerProfile.objects.get(user=request.user)
if not ManagesFund.objects.filter(verified=True, fund=fund, manager=manager).exists() and not request.user.is_staff:
return HttpResponseRedirect('/profile/fund/' + fund_id + '/')
try:
mp = ManagerProfile.objects.get(user__username=request.POST['omnibox'])
fundManager = ManagesFund.objects.get(manager=mp, fund=fund, from_user=True)
if not fundManager.verified:
fundManager.verified = True
fundManager.save()
except ObjectDoesNotExist:
fundManager, created = ManagesFund.objects.get_or_create(manager__user__username=request.POST['omnibox'], fund=fund, from_user=False)
if created:
fundManager.save()
return HttpResponseRedirect('/profile/edit/fund/' + fund_id + '/')
自动完成 VIEWs.py:
@login_required
def managers(request):
managers = ManagerProfile.objects.exclude(user=None)
result = {}
for manager in managers:
result[manager.user.get_full_name()] = manager.user.username
return HttpResponse(json.dumps(result))
自动完成视图传递用户名, add_manager_to_fund() 接受用户名。我该如何解决?