Chris Amico wrote:
[...]
> Awesome. That worked. Thanks all.

> > > 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()

I am very happy to hear that everything's working now.

I am a bit confused though: why not just dropping the total_cost field
from the table? You can retrieve that value on the fly in your views,
no need to have it "hardcoded" in your db. (It's a simple
multiplication, I guess you won't have performance issue for this
change.)

I'd appreciate if anyone can shed some light on this and point out any
drawbacks I can't see.

All the best, Fabio.

-- 
Fabio Natali


--~--~---------~--~----~------------~-------~--~----~
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