Introduce ContentType.objects.get_for_models(*models) and use it in the the auth permissions code. This is a solid performance gain on the test suite. Thanks to ptone for the profiling to find this hotspot, and carl for the review.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16963 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor 2011-10-12 20:51:59 +00:00
parent a5e691e5de
commit f04af7080b
4 changed files with 96 additions and 10 deletions

View file

@ -193,6 +193,13 @@ The ``ContentTypeManager``
:class:`~django.contrib.contenttypes.models.ContentType` instance
representing that model.
.. method:: get_for_models(*models)
Takes a variadic number of model classes, and returns a dictionary
mapping the model classes to the
:class:`~django.contrib.contenttypes.models.ContentType` instances
representing them.
.. method:: get_by_natural_key(app_label, model)
Returns the :class:`~django.contrib.contenttypes.models.ContentType`
@ -319,8 +326,8 @@ creating a ``TaggedItem``::
Due to the way :class:`~django.contrib.contenttypes.generic.GenericForeignKey`
is implemented, you cannot use such fields directly with filters (``filter()``
and ``exclude()``, for example) via the database API. Because a
:class:`~django.contrib.contenttypes.generic.GenericForeignKey` isn't a
and ``exclude()``, for example) via the database API. Because a
:class:`~django.contrib.contenttypes.generic.GenericForeignKey` isn't a
normal field objects, these examples will *not* work::
# This will fail