You have to convert s.price.name to float (or .9 to a DecimalObject if the float-precision should be a problem). This should work: for s in s2: s.price.name = float(s.price.name) * .9 s.price.save()
On Dec 16, 8:43 pm, Greg <[EMAIL PROTECTED]> wrote: > Shabda, > I added the following code to my view: > > for s in s2: > s.price.name *= s.price.name * .9 > s.price.save() > > //////////////////// > > However, I now get the error: > > TypeError at /plush/chandra/antara/108/multi/ > unsupported operand type(s) for *: 'Decimal' and 'float' > > On Dec 16, 12:44 pm, shabda <[EMAIL PROTECTED]> wrote: > > > How about > > > for s in s2: > > s.price.name *= s.price.name * .9 > > s.price.save() > > You are getting a type error coz you can not mutlipy a Model object by > > float, and that is what s.price is. BTW s2[0].price * .9 would not > > have worked as well, because of the same reasons! > > > On Dec 16, 11:08 pm, Greg <[EMAIL PROTECTED]> wrote: > > > > Forest, > > > Here are my models > > > > class Style(models.Model): > > > name = models.CharField(maxlength=200, core=True) > > > image = models.ForeignKey(Photo) > > > collection = models.ForeignKey(Collection, > > > edit_inline=models.TABULAR, num_in_admin=1, num_extra_on_change=3) > > > sandp = models.ManyToManyField(Choice) > > > > class Choice(models.Model): > > > choice = models.ForeignKey(Collection, edit_inline=models.TABULAR, > > > num_in_admin=5) > > > size = models.ForeignKey(Size, core=True) > > > price = models.ForeignKey(Price, core=True) > > > orderdisplay = models.IntegerField() > > > > class Price(models.Model): > > > name = models.DecimalField(max_digits=6, decimal_places=2) > > > > def __str__(self,): > > > return str(self.name) > > > > /////////////////////////////////////// > > > > On Dec 16, 11:56 am, Forest Bond <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > > > On Sun, Dec 16, 2007 at 08:37:08AM -0800, Greg wrote: > > > > > I've tried the following: > > > > > > for s in s2: > > > > > s.price *= s.price * .9 > > > > > > However, I still get the following error: > > > > > > TypeError at /plush/chandra/antara/108/multi/ > > > > > unsupported operand type(s) for *: 'Price' and 'float' > > > > > Can you post your models, please? > > > > > I take it price is a ForeignKey... > > > > > -Forest > > > > -- > > > > Forest Bondhttp://www.alittletooquiet.net > > > > > signature.asc > > > > 1KDownload --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---