Django 从模型的管理表单中直接编辑多个字段
我有下面这样的模型Django 从模型的管理表单中直接编辑多个字段,django,django-admin,Django,Django Admin,我有下面这样的模型 class Product(models.Model): ... class ProductQuantity(models.Model): product = models.ForeignKey('Product') invoice = models.ForeignKey('Invoice') quantity = models.IntegerField() class Invoice(models.Model): ... prod
class Product(models.Model):
...
class ProductQuantity(models.Model):
product = models.ForeignKey('Product')
invoice = models.ForeignKey('Invoice')
quantity = models.IntegerField()
class Invoice(models.Model):
...
products = models.ManyToManyField(Product, through=ProductQuantity)
在django admin中,我想更改数量,而不是打开“新建”对话框,这基本上是管理员的行为,而是选择其中一个对话框(如果有),或者直接在该窗口中键入并更改值。您可以使用:
这样,您就可以直接在发票
管理页面上编辑产品数量
,而无需任何额外的对话框
class ProductQuantityInline(admin.StackedInline):
model = ProductQuantity
class InvoiceAdmin(admin.ModelAdmin):
inlines = [ProductQuantityInline]