I think I am missing something here, but here it goes. I have a model, and
it is a sender for a post_save signal.
class Book(models.Model):
...
created_at = models.DateTimeField(default=timezone.now)
bought = models.BooleanField(default=False)
@receiver(post_save, sender=Book)
def create_sold_log(sender, instance, **kwargs):
if kwargs['created'] and instance.bought:
print('created and instance.bought')
print('k* created', kwargs['created'])
elif kwargs['created']:
print('created only')
print('k* created', kwargs['created'])
else:
print('else...')
Now everytime a book object is saved, the above signal will fire.
So from the below data, after the serializer is saved while the Bought is
True, the kwargs['created'] is True.
data = {
"...": "...",
"bought": True
}
serializer = CustomSerializer(data=data)
if serializer.is_valid():
serializer.save()
And suppose, from the below data, if the bought=False and I save the
serializer, then also kwargs['created'] is True.
data = {
"...": "...",
"bought": False
}
serializer = CustomSerializer(data=data)
if serializer.is_valid():
serializer.save()
But, suppose, later if I update the book object to Bought=True and save it,
the kwargs['created'] is still True.
book.bought = True
book.save()
What am I missing here? Can someone please help me understand. Thank you
--
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 [email protected].
To post to this group, send email to [email protected].
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/CAHSNPWtw1HYP6jz1sNgin%2BDHPrKxH-v7xqzq8mUobSk%2BAQ1_ag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.