Sunday, February 14, 2016

Bug or unaccepted behaviour

Hi Django Experts

I came across something unaccepted while using signal. 


    def clone_creatives(self, src_theme_id):
        themeA = Theme.objects.get(id=src_theme_id)
        self.unit_set.all().delete()
        for u in themeA.unit_set.all():
            u.id = None
            u.theme_id = self.id
            u.save()


@receiver(post_save, sender=Unit)
def unit_post_save(sender, instance, **kwargs):
    print instance.theme.id

 Here instead of printing id of self theme it is still showing id of themeA. 
But if is use
u.theme = self
everything work normal.

What's the different between u.theme = self and u.theme = self.id ?

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aceb013e-6471-4407-b5c4-746cefca62c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment