我有一个模型是这样的:
class Base(models.Model):
pass
class Mixin1(Base):
active = models.BooleanField(default=False)
class Mixin2(Base):
name = models.CharField(max_length=200,blank=False,null=False)
class Organization(Mixin1, Mixin2, Base):
pass
这很好:
^{pr2}$但这并不能:
organization = Organization(name='name', active=True)
organization.save()
Django在构造函数上出错,错误为:
TypeError: 'active' is an invalid keyword argument for this function
a关于混音我有什么遗漏吗?
更新我看到的内容: 使用一个新的PostgreSQL数据库和一个新的shell。
Python 2.7.3 (default, Sep 5 2012, 20:48:07)
[GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.60))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from core.models.organizations import Organization
>>> org1 = Organization(name='name')
>>> org1
<Organization: name>
>>> org1.active = True
>>> org1
<Organization: name>
>>> org1.active
True
>>> org2 = Organization(name='org2',active=True)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "<myprojectpath>/venv/lib/python2.7/site-packages/django/db/models/base.py", line 367, in __init__
raise TypeError("'%s' is an invalid keyword argument for this function" % kwargs.keys()[0])
TypeError: 'active' is an invalid keyword argument for this function
>>>
我把一个旧文件挂起来了。我从组织.py到组织.py. 因为某种原因,组织.pyc被卡住了,正被另一个模型文件导入。令人沮丧的。在
我试过了,我成功了。在
问题应该出在别的地方。在
相关问题 更多 >
编程相关推荐