Skip to content

Instantly share code, notes, and snippets.

@aballah-chamakh
Created July 16, 2019 21:46
Show Gist options
  • Select an option

  • Save aballah-chamakh/1350985fa6272a5306ab2f912b69a4c3 to your computer and use it in GitHub Desktop.

Select an option

Save aballah-chamakh/1350985fa6272a5306ab2f912b69a4c3 to your computer and use it in GitHub Desktop.
from django.db.models.signals import post_save
from django.dispatch import receiver
@receiver(post_save, sender=Article)
def set_analytic_to_article(sender, instance, created, **kwargs):
if created :
analytic_obj = Analytic.objects.create(views=0)
instance.analytic = analytic_obj
instance.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment