Kenneth
I have tried your line and I also removed the call to ('qft') on the
fringe_value. I now get this error. I'm sure there must be something
fundamentally wrong with my approach what am I missing!?!
Model changed to:
def get_fringe_value(self, fringe):
"""select record by ID from the M2M connection fringes"""
ft =
Fringe.objects.select_related().filter(id__in=self.fringe.all()).values()
"""so as not to pass a single value to sum if only one record
# passed from ft then just pass value of percentage"""
if ft.count()<=1:
qft=ft.filter('percentage')
return u'%d' (qft)
"""if more than one record returned from related model do sum on
percentage"""
qft=ft(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' (qft)
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 received is:
Request Method: POST
Request URL: http://localhost:8000/admin/bt4/detail/5/
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
148. super(Detail, self).save()
File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in save
435. self.save_base(using=using, force_insert=force_insert,
force_update=force_update)
File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
save_base
501. rows =
manager.using(using).filter(pk=pk_val)._update(values)
File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in _update
491. return query.get_compiler(self.db).execute_sql(None)
File "/usr/lib/python2.5/site-packages/django/db/models/sql/compiler.py"
in execute_sql
861. cursor = super(SQLUpdateCompiler,
self).execute_sql(result_type)
File "/usr/lib/python2.5/site-packages/django/db/models/sql/compiler.py"
in execute_sql
717. sql, params = self.as_sql()
File "/usr/lib/python2.5/site-packages/django/db/models/sql/compiler.py"
in as_sql
826. val = field.get_db_prep_save(val,
connection=self.connection)
File
"/usr/lib/python2.5/site-packages/django/db/models/fields/subclassing.py"
in inner
28. return func(*args, **kwargs)
File
"/usr/lib/python2.5/site-packages/django/db/models/fields/__init__.py"
in get_db_prep_save
775. return
connection.ops.value_to_db_decimal(self.to_python(value),
File
"/usr/lib/python2.5/site-packages/django/db/models/fields/__init__.py"
in to_python
750. return decimal.Decimal(value)
File "/usr/lib/python2.5/decimal.py" in __new__
650. raise TypeError("Cannot convert %r to Decimal" % value)
Exception Type: TypeError at /admin/bt4/detail/5/
Exception Value: Cannot convert <bound method Detail.get_fringe_value of
<Detail: New Writer for Episode 2 - 1st draft>> to Decimal
Kenneth Gonsalves wrote:
On Fri, 2011-01-21 at 07:33 +0530, Kenneth Gonsalves wrote:
On Thu, 2011-01-20 at 19:04 +0000, Trevor Stanley wrote:
ft = Fringe.objects.select_related().filter(id=self.id).values()
AttributeError: 'str' object has no attribute 'id'
maybe filter(id=self.fringe) or (id=self.fringe_id)
no - that is wrong. filter(id__in=self.fringe.all())
--
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.