我的一个模型是抽象模型,它被另一个模型继承。
class SelectedProduct(models.Model):
sku = fields.SKUField()
description = CharField(_("Description"), max_length=200)
quantity = models.IntegerField(_("Quantity"), default=0)
unit_price = fields.MoneyField(_("Unit price"), default=Decimal("0"))
total_price = fields.MoneyField(_("Total price"), default=Decimal("0"))
class Meta:
abstract = True
继承模型
class OrderItem(SelectedProduct):
order = models.ForeignKey("Order", related_name="items")
现在,如果我在我的视图中运行这个命令 orderItem=OrderItem.objects.all()
并在我的模板{{passed_variable}}
中返回
[<OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, <OrderItem: >, '...(remaining elements truncated)...']
表示没有 id、描述等,如果我{{passed_variable.id}}
在模板中指定,则它什么也不显示。