Merric Mercer schreef:
> Benedict,
> 
> Unfortunately, that is just a typo in my post and not the answer. The 
> actual code has 'for i in qset'.
> 
> The code runs without displaying any errors.  But when I check the 
> "UserPointTypeAggregate" database the field has
> only been updated from the first record of the PointTransaction query set.
> 
> MerMer
> 

The way your function is designed, it will only update 1 record:
you iterate PointTransaction to calculate balance.
Then you use a get on UserPointTypeAggregate which will give you
1 or no objects.
Then you assign the balance value and save it.


If you are running on the development server, you can use print
statements to check you code.
If you're on production, you can use the logging package to achieve
printing debugging messages in a file.

Regards,
Benedict

> 
> 
> Benedict Verheyen wrote:
>> Merric Mercer schreef:
>>   
>>> Help!  I have a function that is  provided below.   When I try the 
>>> individual lines of the function  through the interpretor (Ipython) 
>>> everything works as expected.  For example:-
>>>
>>>  >> qset=PointTransaction.objects.filter etc....   this works fine!! 
>>>
>>> However, when I try to run the function as a whole: Example:-
>>>
>>>  >> admin_sync_agg(user_id=1,points_type=1)  >>
>>>
>>> This runs but it seems that is is not iterating through the query set, 
>>> so only the first record of qset is getting added to the balance.
>>>
>>> Can anybody advise..  it's completely baffling me.  Thanks
>>>
>>> MerMer
>>>
>>>
>>> def admin_sync_agg (user_id,points_type):
>>>     
>>> qset=PointTransaction.objects.filter(user=user_id).filter(points_type=points_type)
>>>     credit=0
>>>     debit=0
>>>     for i in qs:
>>>         credit = credit + i.credit
>>>         debit = credit + i.debit
>>>     balance= credit-debit
>>>     
>>> pa=UserPointTypeAggregate.objects.get(user=user_id,points_type=points_type)
>>>     pa.total_points=balance
>>>     pa.save()
>>>     
>> You are iterating over qs instead of qset.
>>
>> def admin_sync_agg (user_id,points_type):
>> qset=PointTransaction.objects.filter(user=user_id).filter(points_type=points_type)
>>     credit=0
>>     debit=0
>>     for i in qset:
>>         credit = credit + i.credit
>>         debit = credit + i.debit
>>         balance= credit-debit
>> pa=UserPointTypeAggregate.objects.get(user=user_id,points_type=points_type)
>>     pa.total_points=balance
>>     pa.save(
>>
>> (indentation of qset & pa line screwed up using Thunderbird)
>>
>> Regards,
>> Benedict
>>
>>
>>
>>   
> 
> 
> > 
> 


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

Reply via email to