Did you put the Stock model before the OrderItem model? Sometimes this
makes problems.
If you did, what about this as an alternate solution?
class Stock(models.Model):
price = models.FloatField(max_digits=10, decimal_places=2)
class OrderItem(models.Model):
quantity = models.SmallIntegerField(core=True)
item = models.ForeignKey(Stock, core=True)
def _get_total(self):
return self.item.price * self.quantity
total = property(_get_total)
Hope it helps,
G
On 11/19/06, sorrison <[EMAIL PROTECTED]> wrote:
>
> I am in the process of developing a stock ordering system.
>
> I want the total field to be automatically calculated by quantity and
> price fields
>
> when i try and save an order item (in the admin interface) it says
> please correct the errors below without highlighting any of the fields.
>
> This is what i have so far, any help would be much appreciated.
>
> class OrderItem(models.Model):
> ****
> quantity = models.SmallIntegerField(core=True)
> item = models.ForeignKey(Stock, core=True)
> total = models.FloatField(max_digits=10, decimal_places=2,
> blank=True, editable=False)
> def save(self):
> self.total = self.item.price * self.quantity
> super(OrderItem, self).save()
> class Admin:
> fields = (
> (None, {'fields': ('quantity','item',)}),
> )
> list_display = ('item','quantity',total')
>
> class Stock(models.Model):
> ***
> price = models.FloatField(max_digits=10, decimal_places=2)
> ***
>
> Thanks,
>
> Sam Morrison
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---