我在格式化方面遇到了问题。这是我的代码现在的样子:
正如您所看到的,我为每个产品提供了产品字段和价格字段。我如何才能获得它,以便产品和价格与其他所有产品分开?
这是我的代码:
class PurchaseOrder(models.Model):
product = models.ManyToManyField('Product', null =True)
def get_products(self):
return "<br />".join("%s --- $%s" % (p.products, p.price_for_each_item) for p in self.product.all())
get_products.allow_tags = True
get_products.short_description = "Product --- Price"
class Product(models.Model):
products = models.CharField(max_length=256, null =True)
price_for_each_item = models.FloatField(verbose_name = "Price")
def __unicode__(self):
return self.products