djangodjango-contenttypes

Django - ContentType Does Not Exist for own app


I'm trying to learn how to use the ContentTypes framework, I can't seem to get it to find my own apps.

The docs have clear instructions for importing a model from django.contrib.sites, which works for me. However, when I try to substitute my own app and model, I am unsuccessful.

I have a model at MyApp.Events.models.Event. I try to call:

i = ContentType.objects.get(app_label="Events", model="Event")

in response, console prints:

django.contrib.contenttypes.models.DoesNotExist: ContentType matching query does not exist.

I tried this as well which also failed:

i = ContentType.objects.get(app_label="events", model="event")

I have 'django.contrib.contenttypes' as well as this app listed under installed apps. Is there another setting I am missing to enable this functionality?


Solution

  • Since no one else posted it, here is the solution.

    i = ContentType.objects.get(app_label="Events", model="event")

    Even if your model is capitalized in your models.py, it gets saved in all lowercase. I don't know if this is Django's idea of funny or PostgreSQL's, so your mileage may vary.