Kenneth Gonsalves wrote:
On Wed, 2011-01-19 at 22:34 +0000, The Stanley Household wrote:
Happy to send Model if needed but at the moment I'm unable to run the
server to provide admin error report, can C&P from terminal if that
would help with the error.

please copy and paste your code - it is easier for us to help when we
see what you are doing
Kenneth

Here is the code. I've added some notes to try and explain what I think I'm doing

class Fringe(models.Model):
   code = models.CharField(max_length=3, unique = 'true')
   description = models.CharField(max_length=50)
percentage = models.DecimalField(max_digits=6, decimal_places=5, default=0)
   flat_rate = models.IntegerField(blank=True, null=True)
   floor = models.IntegerField(blank=True, null=True)
   ceiling = models.IntegerField(blank=True, null=True)
   total = models.IntegerField(blank=True, null=True)

   def __unicode__(self):
       return self.code


class Detail(models.Model):
   account = models.ForeignKey(Account, related_name= 'account_account')
   description = models.TextField(max_length=200)
   fringe = models.ManyToManyField(Fringe, blank=True, null=True)
   location = models.ForeignKey(Location, blank=True, null=True)
   set_code = models.ForeignKey(Set_Group, blank=True, null=True)
   flag = models.ManyToManyField(Flag, blank=True, null=True)
   quantity = models.IntegerField(blank=True, null=True)
   units = models.CharField(max_length=10)
   multiplier = models.IntegerField(default=1)
   value = models.IntegerField(blank=True, null=True)
   native_total = models.IntegerField(blank=True, null=True)
   currency_code = models.ForeignKey(Currency)
   currency_total = models.IntegerField(blank=True, null=True)
   prev_total = models.IntegerField(default = 0)
   variance = models.IntegerField(blank=True, null=True)
   sort = models.IntegerField()
cash_flow_code = models.ForeignKey(Cashflow, related_name= 'cashflow_code')
   cash_flow_start_week = models.IntegerField(blank=True, null=True)
   cash_flow_weeks = models.IntegerField(blank=True, null=True)
   notes = models.TextField(max_length=200, blank=True, null=True)
fringe_total = models.DecimalField(max_digits=6, decimal_places=5,blank=True, null=True) def __unicode__(self):
       return self.description
class Meta:
       ordering = ['account']
@models.permalink
   def get_absolute_url(self):
       return('bt4_edit_detail', (), { 'object_id':self.id })
def _get_fringe_value(self): ft = Fringe.objects.select_related().filter(id=self).values()"""select record by ID from the M2M connection fringes""" qft=ft#.filter(id=self).values()"""Now obsolete as added to line above will amend when I get it working"""
       """so as not to pass a single value to sum if only one record
            passed from ft then just pass value of percentage"""
       if qft.count()<=1:
           aqft=qft.filter('percentage')
"""if more than one record returned from related model do sum on percentage"""
       else:
           aqft=qft.annotate(sum('percentage'))
"""return value as decimal as it is actually a percentage which will
               be used to create a new value from currency_total on save"""
       return u'%d' (aqft)

   fringe_value = _get_fringe_value('aqft')

   def save(self):
       self.native_total = self.quantity*self.multiplier*self.value
self.currency_total = self.quantity*self.multiplier*self.value*self.currency_code.rate1
       self.variance = self.currency_total-self.prev_total
       self.fringe_total = self.fringe_value
       super(Detail, self).save()

--
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to