次のようなモデルがあります。
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 mixin について何か足りないものはありますか?
私が見ているものの更新: 新しい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
>>>