我目前正在尝试在 Django 2.0 (Python 3.6.3) 中创建一个面向对象的模式,其中包含一个父类 Program 和一些子类 Snippet 和 Software。我看到 model_utils 模块包含一些处理多态性的工具,并尝试复制教程(http://django-model-utils.readthedocs.io/en/latest/managers.html),这是它提供的我的情况:
模型.py
from django.db import models
from model_utils.managers import InheritanceManager
class Program(models.Model):
name = models.CharField(max_length=100)
objects = InheritanceManager()
class Snippet(Program):
code = models.TextField()
class Software(Program):
repoLink = models.URLField()
Django 外壳
>>> from coding.models import Program
>>> programs = Program.objects.select_subclasses()
>>> programs
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "...\py3django\lib\site-packages\django\db\models\query.py", line 248, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "...\py3django\lib\site-packages\django\db\models\query.py", line 292, in __getitem__
qs = self._chain()
File "...\py3django\lib\site-packages\django\db\models\query.py", line 1156, in _chain
obj = self._clone()
File "...\py3django\lib\site-packages\model_utils\managers.py", line 100, in _clone
return super(InheritanceQuerySetMixin, self)._clone(**kwargs)
TypeError: _clone() got an unexpected keyword argument 'subclasses'
我不明白这个错误以及如何修复它,甚至不知道这是我的设计失败还是对 InheritanceManager 的使用不当。那么这个错误消息的来源是什么?