我想覆盖用于在实际模型中保存配置文件的功能。到目前为止,这是我的尝试:
if(check.checked==true){
alert(shippingName.value);
billingName.value = shippingName.value;
billingZip.value = shippingZip.value;
}
else{
billingName.value = "";
billingZip.value = '';
}
如果它在数据库上,只需更新。我这样做是因为我无法从 class Profile(models.Model):
# others
def save(self, *args, **kwargs):
# Object is a new profile if email does not exist
if not Profile.objects.filter(email = self.email).exists():
# save
return super().save(*args, **kwargs)
#object is an existing profile
else:
# update
return super().update(*args, **kwargs)
执行通常的 update_or_create
。任何答案或链接表示赞赏。