Django智能选择多对多字段筛选器“水平”或“筛选器”垂直不允许链接

2024-04-24 05:57:38 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我在django1.10做一个项目。对于这个项目,我使用django智能选择来链接管理面板中的输入。 它工作得很好。但是对于多对多字段链接,如果我使用filter_horizontal/filter_vertical,那么链接就不再起作用了。 github页面中没有解决方案。 我怎样才能解决这个问题?还有其他类似的应用吗?在


Tags: 项目djangogithub面板链接智能页面解决方案
1条回答
网友
1楼 · 发布于 2024-04-24 05:57:38

我有同样的问题,我在库的这个fork中解决了它:https://github.com/jorgecorrea/django-smart-selects 正如您在我的自述版本中看到的,这是在水平模式下使用mi-fork的方法: 模型.py在

from smart_selects.db_fields import ChainedManyToManyField

class Publication(models.Model):
    name = models.CharField(max_length=255)

class Writer(models.Model):
        name = models.CharField(max_length=255)
        publications = models.ManyToManyField('Publication', 
                                              blank=True,
                                              null=True)

class Book(models.Model):
        publication = models.ForeignKey(Publication)
        writer = ChainedManyToManyField(
            Writer,
            horizontal=True,
            verbose_name='writer',
            chained_field="publication",
            chained_model_field="publications",
        )
        name = models.CharField(max_length=255)

通过这个小小的修改,您可以使用django水平模式视图,但不要将该字段添加到adminfilter_horizontal 不需要进行此更改: 管理员py在

^{pr2}$

相关问题 更多 >