from django.contrib.contenttypes.models import ContentType
from django.db.models.signals import post_save
from django.dispatch import receiver
from .tasks import push_new_content

@receiver(post_save)
def post_save_handler(sender, instance, **kwargs):
    instance_type = ContentType.objects.get_for_model(instance.__class__)

    push_new_content.apply_async(countdown=1, kwargs={'instance_type_pk': instance_type.pk,
                                                      'instance_pk': instance.pk})

from django.contrib.contenttypes.models import ContentType
from django.db.models.signals import post_save
from django.dispatch import receiver
from .tasks import push_new_content

@receiver(post_save)
def post_save_handler(sender, instance, **kwargs):
    if ContentType.objects.exists():
        instance_type = ContentType.objects.get_for_model(instance.__class__)

        push_new_content.apply_async(countdown=1, kwargs={'instance_type_pk': instance_type.pk,
                                                          'instance_pk': instance.pk})

Fix initial migration until ContentType is available
Fix initial migration until ContentType is available

  from django.contrib.contenttypes.models import ContentType
  from django.db.models.signals import post_save
  from django.dispatch import receiver
  from .tasks import push_new_content
  
  @receiver(post_save)
  def post_save_handler(sender, instance, **kwargs):
+     if ContentType.objects.exists():
-     instance_type = ContentType.objects.get_for_model(instance.__class__)
+         instance_type = ContentType.objects.get_for_model(instance.__class__)
  
-     push_new_content.apply_async(countdown=1, kwargs={'instance_type_pk': instance_type.pk,
+         push_new_content.apply_async(countdown=1, kwargs={'instance_type_pk': instance_type.pk,
-                                                       'instance_pk': instance.pk})
+                                                           'instance_pk': instance.pk})
  
Fix initial migration until ContentType is available
## Code Before:
from django.contrib.contenttypes.models import ContentType
from django.db.models.signals import post_save
from django.dispatch import receiver
from .tasks import push_new_content

@receiver(post_save)
def post_save_handler(sender, instance, **kwargs):
    instance_type = ContentType.objects.get_for_model(instance.__class__)

    push_new_content.apply_async(countdown=1, kwargs={'instance_type_pk': instance_type.pk,
                                                      'instance_pk': instance.pk})

## Instruction:
Fix initial migration until ContentType is available
## Code After:
from django.contrib.contenttypes.models import ContentType
from django.db.models.signals import post_save
from django.dispatch import receiver
from .tasks import push_new_content

@receiver(post_save)
def post_save_handler(sender, instance, **kwargs):
    if ContentType.objects.exists():
        instance_type = ContentType.objects.get_for_model(instance.__class__)

        push_new_content.apply_async(countdown=1, kwargs={'instance_type_pk': instance_type.pk,
                                                          'instance_pk': instance.pk})
