djangocachingcontenttype

Deleted models still show up as ContentType choices in Django?


I am limiting the ContentType choices for a Generic Relation using limit_choices_to but it shows models that no longer exist. For example with this code:

 employer_content_type = models.ForeignKey(ContentType,
    limit_choices_to={"model__in": ('venue', 'festival')}, related_name="employer")

I get a list of choices that has duplicates, i.e. festival, festival, venue, venue

However when I limit the choices by app rather then just models like this:

    employer_content_type = models.ForeignKey(ContentType,
          limit_choices_to={'app_label': 'contacts'}, related_name="employer")

I get a list of all of the models with no duplicates, i.e. address, email, festival, venue

At one point in my development I created a new app ("contacts") that was a duplicate of an older app. All of the models had the same names etc. At first I thought that this was causing the duplicates but the problem didn't go away after I removed the old app from settings.py and deleted the old models form the database.

I think it is a cache issue but I never set up caching!

SO how do I either clear the cache, or limit the choices by model and app at the same time.

Thanks for your help!

Note: Unfortunately I couldnt add pictures so its a little hard to describe!


Solution

  • Look for contentypes_contentype db table and delete obsolete models there. syncdb should also prompt you to delete obsolete models from content type table.