django-admin:“super() 参数 1 必须是类型,而不是 None”当重写保存方法时

发布于 2024-10-07 11:43:53 字数 357 浏览 0 评论 0 原文

好吧,另一个无用的错误导致我花了一个小时试图解决这个问题。

我有一个模型“CompanyProfile”,直到最近一直在工作,但现在当我尝试通过管理员保存模型时,我收到一个错误,似乎告诉我对象引用为空。我不知道如何排序。

我像往常一样做一切:

def save(self, force_insert=False, force_update=False):
    super(CompanyProfile, self).save(force_insert, force_update)

我重新启动了服务器,重新安装了 django,清除了数据库,但仍然没有运气。有人有任何想法或以前遇到过这个问题吗?

Well, another unhelpful error has caused me to spend an hour trying to sort this problem.

I have a model 'CompanyProfile' that has been working until recently, but now when i try to save the model through the admin, I get an error which seems to be telling me that the Object reference is null. I have no idea how to sort this.

I'm doing everything as usual:

def save(self, force_insert=False, force_update=False):
    super(CompanyProfile, self).save(force_insert, force_update)

I've restarted the server, reinstalled django, cleared the database, and still no luck. Anyone have any ideas or had this problem before?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

倾其所爱 2024-10-14 11:43:53

也许这是一个循环导入问题?
http://markmail.org/message/zothlfayqkbidqfh# query:+page:1+mid:3cnpcw3e4cgo3cas+state:results

在这里的示例中,他在信号中有一个 import 语句,这是罪魁祸首。

您可以检查 globals() 是否有类似症状。

Maybe it's a cyclic import issue?
http://markmail.org/message/zothlfayqkbidqfh#query:+page:1+mid:3cnpcw3e4cgo3cas+state:results

In the example here, he had an import statement in a signal that was the culprit.

You could check globals() for similar symptoms..

怀念你的温柔 2024-10-14 11:43:53

重写模型方法时需要使用 args/kwargs: http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods

通过考试也很重要
通过论证可以
传递给模型方法——那就是
*args、**kwargs 位的作用是什么。
Django 会不时地扩展
内置模型的功能
方法,添加新参数。如果你
在你的方法中使用 *args, **kwargs
定义,你可以保证
您的代码将自动支持
添加这些参数时。

You need to use args/kwargs when overriding model methods: http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods

It's also important that you pass
through the arguments that can be
passed to the model method -- that's
what the *args, **kwargs bit does.
Django will, from time to time, extend
the capabilities of built-in model
methods, adding new arguments. If you
use *args, **kwargs in your method
definitions, you are guaranteed that
your code will automatically support
those arguments when they are added.

长安忆 2024-10-14 11:43:53

尝试遵循 save() 覆盖示例rel="nofollow">此处的文档。请注意 *args、**kwargs 的使用。如果这不起作用,那么事情就严重混乱了。

Try following the save() override example from the docs here. Note the use of *args, **kwargs. If that doesn't work then something is serious messed up.

冷情妓 2024-10-14 11:43:53

只是一个快速猜测,但是这个保存方法肯定是 CompanyProfile 模型类的一部分吗?您的缩进是否正确?

Just a quick guess, but is this save method definately part of the CompanyProfile models class and is your indentation correct?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文