所以我正在制作一个更新表单,我希望允许用户更新他想要更新的字段,并让其余部分保持不变。但是django不会让他单独离开build_name字段而不进行任何更改,因为build_name是一个主键并且必须是唯一的。然而,对象本身触发了名称已经存在的事实。
Map<String, List<String>> map = new Hashmap<>();
String currentTitle = null;
for(int i = 0; i<range.numCharacterRuns(); i++){
CharacterRun cr = range.getCharacterRun(i);
//if the cr is bold, add it as a title
if(cr.isBold()){
currentTitle = cr.text();
map.put(currentTitle, new ArrayList<String>());
}else{
//if the cr is not bold, get the last inserted title and
//add the cr to its String list
List<String> list = map.get(currentTitle);
if(list != null){
list.add(cr.text());
map.put(currentTitle, list);
}
}
}
这是create.html
def update(request, id):
title = 'Updating Build'
the_name = champBuild.objects.filter(pk=id).values_list('build_name', flat=True)
form = champBuildUpdateForm(request.POST or None, initial={'build_name': str(the_name)[3:-2]})
if form.is_valid():
champBuild.objects.filter(pk=id).update(build_name=form.cleaned_data.get('build_name'))
return HttpResponseRedirect('/lolBuilds/detail/{}'.format(form.cleaned_data.get('build_name')))
context = {
'title': title,
'form': form
}
return render(request, 'lolBuilds/update.html', context)
当我点击更新而不更改构建名称字段时会发生这种情况。