擅长:python、mysql、java
<p>问题是,在创建新对象时,首先获取原始对象并仅更改所需的内容</p>
<pre><code>#Update
// Change this to get the object
modelwithdata = get_object_or_404(Country, pk=id)
// Change only the fields you need to
modelwithdata.countryname=request.POST.get('countryname')
modelwithdata.countryincharge_id=request.POST.get('countryincharge')
modelwithdata.modifiedtime = timezone.now()
modelwithdata.modifiedby = request.user.id
//Dont need this
// modelwithdata.id = id
//Save the new model
modelwithdata.save()
</code></pre>