我有一个看起来像这样的模型:
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
这工作正常:
organization = Organization(name='name')
organization.active = True
organization.save()
但这不会:
organization = Organization(name='name', active=True)
organization.save()
Django 在构造函数上出错:
TypeError: 'active' is an invalid keyword argument for this function
a 关于mixins,我有什么遗漏吗?
我所看到的更新: 使用新的 PostgreSQL 数据库和新的外壳。
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
>>>