On Mon, 2008-08-25 at 15:58 -0700, Chris Amico wrote:
> Changed the variable names to make it a little more readable. Method
> now returns "amount" (formerly "total"):
> 
> Class Item(models.Model):
>     name = models.CharField(max_length=100)
>     price = models.DecimalField(max_digits=9, decimal_places=2)
>     quantity = models.IntegerField(default=1)
>     total_cost = models.DecimalField(max_digits=12,
>                                      decimal_places=2,
>                                      blank=True,
>                                      null=True,
>                                      editable=False)
> 
>     def calc_total(self):
>         amount = (self.price * self.quantity)
>         return amount
> 
>     def save(self):
>         self.total_cost = self.calc_total()
>         super(Item, self).save()
> 
> 
> Now I get a different error when I try to save an Item:
> 
> OperationalError at /admin/spending/item/add/
> (1054, "Unknown column 'total_cost' in 'field list'")
> 

Your earlier model had a bug -- two things called total_cost. The second
thing with that name (the method) completely hid the first thing. It
wasn't just something that gave Karen a headache; it was a real bug. So
when you ran "syncdb", there was no field called total_cost because the
"total_cost" attribute was a method. Thus, you have added a new field to
the model now that you have removed the method.

You'll either have to update the database table manually, or drop and
recreate that model's table (look at the sqlreset command for
django-admin.py).

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to