Re: m2m_changed signal can not distinguish between existing and newly added instances

2013-02-07 Thread vijay shanker
well .. odd .. replying my own post .. 
kwargs['action'] 

A string indicating the type of update that is done on the relation. This 
can be one of the following:
"pre_add"Sent *before* one or more objects are added to the relation.
"post_add"Sent *after* one or more objects are added to the relation.
"pre_remove"Sent *before* one or more objects are removed from the relation.
"post_remove"Sent *after* one or more objects are removed from the relation.
"pre_clear"Sent *before* the relation is cleared."post_clear"Sent *after*the 
relation is cleared. 


m2m_changed calls the handle_something function with different 
kwargs['action'] value which can help you differentiate between them.

On Friday, June 8, 2012 7:24:34 PM UTC+5:30, vijay shanker wrote:
>
> hi 
> i have this model  Client_Order 
> i want to do some manipulation each time a new pakg is added to this 
> field. 
> i used m2m_changed signal, but it cant distinguish between existing 
> instances attached and the newly added ones. 
> both post_add and pre_add show the same number of instances .. i.e if 
> a.b were attached and i added c instance to it .. both post_add and 
> pre_add give the same pk_set in kwargs 
>
> ACTV_STATUS = ( 
> ('Active','Active'), 
> ('Inactive','Inactive'), 
> ) 
>
> class Client_Order(models.Model): 
> order_name  = models.CharField(max_length=300) 
> order_desc  = models.TextField(verbose_name="Order 
> Description") 
> order_client= models.ForeignKey(Client_sda) 
> order_active_status = models.CharField(choices = ACTV_STATUS, 
> max_length=300) 
> order_pakages   = models.ManyToManyField(Pakage, 
> help_text="Please attach a maximum of 5 packages only. ") 
> discount= models.IntegerField(default=0) 
> total_amount= models.IntegerField() 
> order_booking_date  = models.DateField() 
> order_expiry_date   = models.DateField() 
>
> @receiver(m2m_changed) 
> def handle_something(sender, instance, signal,*args, **kwargs): 
> print kwargs 
> print 'pk_set->',kwargs['pk_set'] 
>
> how do i distinguish between newly added instances from previously 
> added ones ? 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




m2m_changed signal can not distinguish between existing and newly added instances

2012-06-08 Thread vijay shanker
hi
i have this model  Client_Order
i want to do some manipulation each time a new pakg is added to this
field.
i used m2m_changed signal, but it cant distinguish between existing
instances attached and the newly added ones.
both post_add and pre_add show the same number of instances .. i.e if
a.b were attached and i added c instance to it .. both post_add and
pre_add give the same pk_set in kwargs

ACTV_STATUS = (
('Active','Active'),
('Inactive','Inactive'),
)

class Client_Order(models.Model):
order_name  = models.CharField(max_length=300)
order_desc  = models.TextField(verbose_name="Order
Description")
order_client= models.ForeignKey(Client_sda)
order_active_status = models.CharField(choices = ACTV_STATUS,
max_length=300)
order_pakages   = models.ManyToManyField(Pakage,
help_text="Please attach a maximum of 5 packages only. ")
discount= models.IntegerField(default=0)
total_amount= models.IntegerField()
order_booking_date  = models.DateField()
order_expiry_date   = models.DateField()

@receiver(m2m_changed)
def handle_something(sender, instance, signal,*args, **kwargs):
print kwargs
print 'pk_set->',kwargs['pk_set']

how do i distinguish between newly added instances from previously
added ones ?

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