开发者

django-admin: "super() argument 1 must be type, not None" when overriding save method

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?


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..


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜