Skip to content

Instantly share code, notes, and snippets.

@toast38coza
Created April 11, 2011 23:14
Show Gist options
  • Save toast38coza/914587 to your computer and use it in GitHub Desktop.
Save toast38coza/914587 to your computer and use it in GitHub Desktop.
Get the content_type_id for the changed item on save in the post_save signal
from django.dispatch import receiver
from django.db.models.signals import post_save
from django.contrib.contenttypes.models import ContentType
@receiver(post_save)
def model_saved(sender, instance, signal, *args, **kwargs):
app_label = sender._meta.app_label
model_name = sender._meta.module_name
content_type = ContentType.objects.get(app_label=app_label, model=model_name)
content_type_id = content_type.id
# do something useful with the content_type_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment