Reputation: 109
I will running something function if created new object. But i will not run if the object already exists
Example:
class Model(models.Model):
test = models.Charfield(max_length=255)
if created new object(!):
requests.POST(blablabla)
Upvotes: 0
Views: 137
Reputation: 5669
You can use django post_save
signal:
from django.db.models.signals import post_save
from django.dispatch import receiver
from myapp.models import MyModel
@receiver(post_save, sender=MyModel)
def my_handler(sender, instance, created, **kwargs):
if created:
# do what you want
# instance is your just created model instance
More about signals in Django docs.
Upvotes: 2