The pre_save signal seems to be called twice when adding the model
object to db and change to the instance object during pre_save don't
get saved.

{{

def do_negative_amount(sender, instance, signal, *args, **kwargs):
    print instance.transaction_type

    if instance.id is None and instance.transaction_type == 'M':
        instance.amount = float(instance.amount) * float(-1)

class FinancialTransaction(models.Model):
    transaction_type = models.ForeignKey(TransactionType)
    ...

dispatch.connect(do_negative_amount, signal=signals.pre_save,
sender=FinancialTransaction)

}}

I registered the FinancialTransaction with Admin (nfa branch).

No 1.) The above print statement in the do_negative_amount() function
prints twice when I click the add button 'once' in the nfa to add the
entry to db. Surely this shouldn't happen?

No 2.) The *** instance.amount = float(instance.amount) * float(-1)
*** in the do_negative_amount() function does make the change to the
instance.amount attribute (e.g. 850 becomes -850). However, the change
is not reflected in the new database entry. (In db, its 850 instead of
the modified -850.) I would expect the instance reference passed
through the do_negative_amount() function to be modifiable. Its a
pre_save signal / step. Maybe I'm missing something.

Regards,
-Alen Ribic

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