Django InlineAdmin for ManyToMany 字段没有明确命名通过

Django InlineAdmin for ManyToMany field which doesn't have an explicitly named through

我有两个模型,具有 ManyToMany 关系:

App1:

class Foo:
    fld = models.CharField(null=True, blank=True)

App2:

class Bar:
    foos = models.ManyToManyField(Foo, blank=True)

现在,在 Bar 的管理员视图中,我想展示 foos。我不能简单地将 foos 列为 ManyToMany 字段,我收到一条错误消息。

所以我尝试这样做:

class BarFooInline(admin.TabularInline):
    model = Bar_foos

class BarAdmin(admin.ModelAdmin):
    model = Bar
    inlines = [BarFooInline, ]

admin.site.register(Bar, BarAdmin)

我通过查看 Bar 的 Meta 获得了名称 Bar_foosBar.foos.through 将其作为适当的 models.Bar_foos 产生。但是由于我没有明确命名 through,它实际上并不在 models.py 中,所以我无法导入它。我该怎么办?

我现在不想创建一个through,因为我已经在table中有了一大堆关联信息,而且我有一种感觉,不会神奇地将数据迁移到新的命名关联实体的 table (https://mounirmesselmeni.github.io/2013/07/28/migrate-django-manytomany-field-to-manytomany-through-with-south/).

此外,我无法将 ManyToMany 字段从 App2 移动到 App1

class BarFooInline(admin.TabularInine):
    models = Bar.foos.through

class BarAdmin(admin.ModelAdmin):
    model = Bar
    inlines = [BarFooInline]
    exclude = ['foos']

Working with many-to-many models.