I have mymodels.py:class Hotel(models.Model):name = models.CharField(max_length=20)currency = models.ForeignKey(Currency)class Currency(models.Mode):code = models.CharField(max_length=3)name = models.CharField(max_length=10)
Whenever thecurrencyfield in hotel is changing I need to be able to do something. So I have a function like :
@receiver(pre_save,sender=Hotel)def update_something(sender,**kwargs)obj = kwargs['instance']old_object = Hotel.objects.get(pk=obj.pk)''' Now I can do anything here comparing the oldo object with the instance '''Now I can do anything here comparing the oldo object with the instance'''The thing is I don't want to make a query for this, since then the purpose of signals becomes stupid and I become a fool.
So I should be able to do something like :updated = kwargs['update_fields']new_currency = updated['currency']
Is their a way I can find out that change for ONLY one particular field saycurrency,instead of doing a query like this. I want to get the changes related to thecurrencyforeign key and update things before I save.
Thanks
-- 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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment