Created
April 11, 2011 23:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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