类型对象'发票'没有属性'对象'

时间:2016-05-11 06:08:25

标签: django django-models django-views

以下是models.py

list/book/[id]

这里是views.py,其中正在创建Invoice对象,但它抛出错误:

class InvoiceItem(models.Model):
    invoice = models.ForeignKey("Invoice")
    item = models.ForeignKey(StoreProduct)
    description = models.CharField(max_length=200 , null=True , blank=True )
    quantity = models.PositiveIntegerField(default=1)
    size = models.CharField(max_length=200 , null=True , blank=True)
    line_item_total=models.DecimalField(max_digits=10 , decimal_places=2)

    def __unicode__(self):
        return self.item.product.title

class Invoice(models.Model):
    order = models.ForeignKey(Order)
    user = models.ForeignKey(settings.AUTH_USER_MODEL , null=True , blank=True)
    items = models.ManyToManyField(StoreProduct, through=InvoiceItem)
    timestamp = models.DateTimeField(auto_now_add = True , auto_now=False)
    updated = models.DateTimeField(auto_now_add=False , auto_now=True)
    delivery_charges = models.PositiveIntegerField(default=50)
    original_total = models.DecimalField(max_digits=10 , decimal_places=2)
    final_total = models.DecimalField(max_digits=50 , decimal_places=2)

    def __unicode__(self):
        return str(self.id)

这里是追溯

invoice = Invoice.objects.create(order=new_order , original_total=0 , final_total=0)
invoice.user=user_checkout
invoice.save()

为什么我收到上述错误,我该怎么做才能解决这个问题?谢谢。

0 个答案:

没有答案