如何解决Django-smart-select 在 manytomany 字段上使用直通模型
我正在尝试实施 django-smart-selects,但 Docs 中未涵盖我的情况。 它们涵盖了两种情况 - 那些是
class Continent(models.Model):
name = models.CharField(max_length=255)
class Country(models.Model):
continent = models.**ForeignKey**(Continent)
name = models.CharField(max_length=255)
class Location(models.Model):
continent = models.ForeignKey(Continent)
country = models.ForeignKey(Country)
area = models.ForeignKey(Area)
city = models.CharField(max_length=50)
street = models.CharField(max_length=100)
和
class Continent(models.Model):
name = models.CharField(max_length=255)
class Country(models.Model):
continent = models.**ManyToMany**(Continent)
name = models.CharField(max_length=255)
class Location(models.Model):
continent = models.ForeignKey(Continent)
country = models.ForeignKey(Country)
area = models.ForeignKey(Area)
city = models.CharField(max_length=50)
street = models.CharField(max_length=100)
但是,我的场景看起来像这样 - 有一个额外的直通模型;
class Continent(models.Model):
name = models.CharField(max_length=255)
class Country(models.Model):
continent = models.**ManyToMany**(Continent,through='CountryToContinent")
name = models.CharField(max_length=255)
class CountryToContinent(models.Model):
continent = models.ForeignKey(Continent)
name = models.ForeignKey(Country)
class Location(models.Model):
continent = models.ForeignKey(Continent)
country = models.ForeignKey(Country)
area = models.ForeignKey(Area)
city = models.CharField(max_length=50)
street = models.CharField(max_length=100)
在 django admin 中,我已经注册了 Location
模型,并且我有一个 tabular inline
带有 continent
和国家/地区字段,但是由于存在直通模型,链式选择不起作用。任何指导或提示将不胜感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。