Sunday, February 14, 2016

Re: Bug or unaccepted behaviour

Hi, 

Would need to see more of you code to understand exactly what you want to do.

Regarding your question. It doesn't make sense, but I think you are asking the difference between "u.theme_id = self.id" and "u.theme = self"? I don't know exactly the difference, but I do know that you shouldn't handle the foreignkey references yourself. You SHOULD use "u.theme = self", and I think the reason for this is that the save method changes the u.theme_id via the u.theme object.

I always handle the foreign keys with the objects rather then the id's.

Regards,

Andréas

2016-02-14 12:04 GMT+01:00 Arink Verma <arinkverma@gmail.com>:
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.

--
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/CALXYUbm%2BB6Lqgf7Jiox%2BDoZyuGkUeS4vKAcCzONrk7iTOdit4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment