我有以下型号:
class Provider(models.Model):
name = models.CharField()
...
class Article(models.Model):
provider = models.ManyToManyField(Provider)
...
class Invoice(models.Model):
provider = models.ForeignKey(Provider)
...
class ArticleInvoice(models.Model):
article = models.ForeignKey(Article)
invoice = models.ForeignKey(Invoice)
... #qty, status, etc
我的管理员看起来像:
class ArticleInvoiceInline(admin.TabularInline):
model = ArticleInvoice
class InvoiceAdmin(models.Model):
inlines = [ArticleInvoiceInline]
admin.site.register(Invoice, InvoiceAdmin)
问题:
当我创建发票时,我必须选择提供商,然后添加一些 ArticleInvoice , ArticleInvoice 有一个文章哪个提供商,当我为 ArticleInvoice 选择文章时,它会显示所有文章
我想应用过滤器,因此我只能在InvoiceAdmin中创建 ArticleInvoice ,其中文章具有相同的提供商 发票