使用抽象类对多对多关系进行建模(错误:fields.E331)

时间:2019-06-14 10:05:05

标签: python django django-models

我测试了以下代码:https://code.djangoproject.com/ticket/11760# 但这不起作用

class ClassA(models.Model):
    pass

class AbstractClass(models.Model):
    name = models.ManyToManyField(ClassA, related_name = '%(class)s_name', through = 'ClassA_%(class)s')
    class Meta:
        abstract = True

class MyClass(AbstractClass):
    pass

class ClassA_MyClass(models.Model):
    class_a=models.ForeignKey(ClassA, on_delete=models.CASCADE)
    my_class=models.ForeignKey(MyClass, on_delete=models.CASCADE)

我遇到此错误:

(fields.E331) Field specifies a many-to-many relation through model 'ClassA_%(class)s', which has not been installed.

0 个答案:

没有答案