I am new to programming and struggling slightly with all sorts of
things but I'm determined to understand it.

I am trying to take the field value(Decimal) associated with
Fringe.percentage and pass it to Detail.fringe_total where the fringe
id matches self fringe id.  I then need to sum it if there is more
than one fringe selected.

I received the above error having changed my code following an earlier
posting.  Models and full error message below

Any ideas welcome - also if there are any glaring errors in my
approach or coding it would be great to get the heads up.

MODEL:
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__in=self.fringe.all()).values()
                if ft.count()==0:
                        return u'%d'(0)
                if ft.count()==1:
                        qft=ft.get('percentage')
                return u'%d'(qft)
                if ft.count()>=2:
                        aqft=ft.aggregate(sum('percentage'))
                return u'%d'(aqft)

        fringe_value = get_fringe_value


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

ERROR:

Environment:

Request Method: POST
Request URL: http://localhost:8000/admin/bt4/detail/1/
Django Version: 1.2.1
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.comments',
 'django.contrib.markup',
 'mysite.bt4',
 'coltrane',
 'tagging',
 'cab',
 'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
  100.                     response = callback(request,
*callback_args, **callback_kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/
options.py" in wrapper
  239.                 return self.admin_site.admin_view(view)(*args,
**kwargs)
File "/usr/lib/python2.5/site-packages/django/utils/decorators.py" in
_wrapped_view
  76.                     response = view_func(request, *args,
**kwargs)
File "/usr/lib/python2.5/site-packages/django/views/decorators/
cache.py" in _wrapped_view_func
  69.         response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
in inner
  190.             return view(request, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/utils/decorators.py" in
_wrapper
  21.             return decorator(bound_func)(*args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/utils/decorators.py" in
_wrapped_view
  76.                     response = view_func(request, *args,
**kwargs)
File "/usr/lib/python2.5/site-packages/django/utils/decorators.py" in
bound_func
  17.                 return func(self, *args2, **kwargs2)
File "/usr/lib/python2.5/site-packages/django/db/transaction.py" in
_commit_on_success
  299.                     res = func(*args, **kw)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/
options.py" in change_view
  895.                 self.save_model(request, new_object, form,
change=True)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/
options.py" in save_model
  597.         obj.save()
File "/home/trevor/1stdjangoproject/mysite/../mysite/bt4/models.py" in
save
  146.          self.fringe_total = self.fringe_value()
File "/home/trevor/1stdjangoproject/mysite/../mysite/bt4/models.py" in
get_fringe_value
  134.          return u'%d'(qft)

Exception Type: UnboundLocalError at /admin/bt4/detail/1/
Exception Value: local variable 'qft' referenced before assignment

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