djongo数据库连接器内联的Django管理中遇到错误

我使用ArrayReferenceField而不是ManyToManyField,因为我使用djongo作为数据库连接器。我希望此字段在django管理站点中显示为内联模型。但是我收到错误AttributeError: 'ArrayReferenceDescriptor' object has no attribute 'through'。我知道ArrayReferenceField不会在数据库中创建中间模型。那么如何在django管理员中成功显示为内联字段?

我的模特:

class Synonym(models.Model):
    base_name = models.CharField(
        blank=False,max_length=5000,verbose_name='Base Entity Value',help_text='The entity value for which you want to provide the synonym.',)

    extra_name = models.CharField(
        blank=False,verbose_name='A synonym',help_text='Synonyms of the base entity value.',)

    class Meta:
        # abstract = True
        ordering = ['base_name']

    def __str__(self):
        return self.base_name

class qa(DirtyFieldsMixin,models.Model):
    synonyms = models.ArrayReferenceField(
        blank=True,null=True,to=Synonym,on_delete=models.SET_NULL,help_text='Synonyms of the entities of the question.',)

在admin.py中:

class SynonymInline(admin.TabularInline):
    model = qa.synonyms.through


class SynonymAdmin(admin.ModelAdmin):
    inlines = [
        SynonymInline,]


@admin.register(qa)
class qaAdmin(admin.ModelAdmin):
    # form = qaModelForm

    list_display = ('question','answer','module','intent','display_entities_name')

    list_filter = ('module','username',)

    inlines = [
        SynonymInline,]
kangzilong 回答:djongo数据库连接器内联的Django管理中遇到错误

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3124741.html

大家都在问