Django自定义保存不工作(Django custom save not working)
所以我有以下型号:
class Info(models.Model): user_id = models.BigIntegerField(primary_key=True) #... def save(self,*args,**kwargs): print 1 is_created = False if not self.pk: print 2 is_created = True super(Info, self).save(*args, **kwargs) print 3 if is_created: print 4 signals.info_created.send(sender=self.__class__,info=self)
现在我有那些打印语句来跟踪发生了什么。当我运行
Info.create(...)
或info = Info(...) info.save()
我得到以下输出:
1 3
这表明
if not self.pk
语句被评估为false。 现在我假设这是因为我有一个自定义主键需要在创建该对象时给出。 所以这是我的问题: 我的假设是正确的吗? 无论是否,我如何才能使这个自定义保存合作?So I have the following model:
class Info(models.Model): user_id = models.BigIntegerField(primary_key=True) #... def save(self,*args,**kwargs): print 1 is_created = False if not self.pk: print 2 is_created = True super(Info, self).save(*args, **kwargs) print 3 if is_created: print 4 signals.info_created.send(sender=self.__class__,info=self)
now I have those print statements to keep track of what is going on.when I run either
Info.create(...)
orinfo = Info(...) info.save()
I get the following output:
1 3
which suggests that the
if not self.pk
statement evaluated to false. Now I assume this is because I have a custom primary key that needs to be given on the creation of that object. So here is my question: is my assumption correct? Regardless if it is or is not, how can I get this custom save to cooperate?
原文:
最满意答案
抛开模态(我在这里看不到模态代码),你可以像这样在你的
+= " myBtn"
行中添加一个空格,以成功地给按钮一个'myBtn'的ID。 如果没有,只需使用简单的“=”并为其提供所需的所有ID,以空格分隔。Modal aside (I see no modal code here), you could probably add a space to your
+= " myBtn"
line like so, to successfully give the button an ID of 'myBtn'. If not, just use a plain "=" and give it all the IDs it needs, separated by a space.
相关问答
更多-
未捕获的参考错误VueJS(Uncaught reference error VueJS)[2022-06-06]
您收到“Vue未定义”错误,因为您没有在HeightCard.js文件中导入Vue 。 但是,您无法正确导出Vue组件,因此即使将Vue导入该文件,您的HeightCard组件也将在导入它的文件中undefined 。 最简单的解决方案是将HeightCard组件更改为单个文件组件,就像父组件一样。 将文件HeightCard.vue ,然后将其结构如下:快速尝试后,我设法重现了您提到的错误。 如果您的函数具有外部js文件,而这些文件依赖于其他JS库,则必须首先加载该库 ,然后再加载依赖于您的函数的JS文件。 例如,这不起作用: 因为,JS解释器搜索$ before甚至被加载和定义。 但是,这将工作:调试未捕获的参考错误(Debugging Uncaught Reference Error)[2022-07-31]
HTML从上到下加载,脚本也按照相同的顺序加载,并在加载后立即执行。 在这里你先加载了thumbnails.js ,然后加载了jquery.js ,所以thumbnail.js首先被加载,并且它使用了jQuery的$ object / function,并且由于jquery还没有被加载,所以你不会在页面上看到这个错误。 处理HTML中脚本标记的顺序。 其次,我不确定这个Thumbnail.js ,它是如何工作的,但它是一个$(document).ready(function () { //your code ...获取未捕获的参考错误:Button1_Click未定义(Getting Uncaught Reference Error:Button1_Click is not defined)[2022-03-08]
您的按钮未在服务器端定义。 您需要使用runat = "server"按钮并将onclick事件更改为onserverclick如下所示 而是使用Asp. ...如果您使用的是D3 v4.x,则正确的语法是d3.queue 。 所以,它应该是: d3.queue() .defer(d3.json, "us.json") .await(function (err, US) { var states = svg.append("g") .attr("class", "states") .selectAll("g") .data(topojson.feature(US, ...getSelMag是分配给magnitude的函数的名称,它在没有任何参数的情况下立即被调用。 所以你留下: var value = Number(undefined.value) //^ Cannot read property 'value' of undefined return value 即使你通过论证,我认为你误解了IIFE的使用,也许是一般的功能。 名称getSelMag在范围内不可用,变量magnitude为,因此ReferenceError: get ...能够解决问题。 刚刚删除并重新添加了文件和文件传输插件。 cordova plugin rm org.apache.cordova.file和cordova plugin rm org.apache.cordova.file-transfer删除。 cordova plugin add org.apache.cordova.file和cordova plugin add org.apache.cordova.file-transfer添加。 它可能会告诉你这些插件很快就会被弃用或类似的东西。 您还可以选择使 ...未捕获的参考错误 - 来自href的[h3>的onClick函数[重复](Uncaught Reference Error - onClick function of
from href [duplicate])
[2021-07-09]你注射了不正确的脚本。 使用下一个语法: You have injected you script incorrect. Use next syntax:更改按钮功能时出现未捕获参考错误(Getting Uncaught Reference Error when changing the function of a button)[2023-10-04]
抛开模态(我在这里看不到模态代码),你可以像这样在你的+= " myBtn"行中添加一个空格,以成功地给按钮一个'myBtn'的ID。 如果没有,只需使用简单的“=”并为其提供所需的所有ID,以空格分隔。 Modal aside (I see no modal code here), you could probably add a space to your += " myBtn" line like so, to successfully give the button an ID of 'myBtn' ...codepen示例( https://codepen.io/Teeke/pen/mRgWLg )中的问题是第355行存在JavaScript错误: setText(playButton, "Play"); 变量playButton尚未定义。 这阻止了其余的JavaScript工作。 一旦我注释掉了对playButton的所有引用,就会按预期执行intro.js代码。 The issue in the codepen example (https://codepen.io/Teeke/pen/mRgWLg) ...相关文章
更多- Solr: a custom Search RequestHandler
- Hadoop0.20+ custom MultipleOutputFormat
- Working on Free Software
- solr自定义排序
- solr 使用自定义的 QueryParser
- solr 使用自定义的 QueryParser
- Solr 使用自定义 Query Parser
- Solr 使用自定义 Query Parser
- 微信公众平台自定义菜单及高级接口PHP SDK
- 微信公众平台自定义菜单及高级接口PHP SDK(转)
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)