mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #18399 – Added a way to get ContentTypes for proxy models
Added kwargs for_concrete_model and for_concrete_models to ContentType methods get_for_model() and get_for_models(). By setting the flag to False, it is possible to get the contenttype for proxy models.
This commit is contained in:
parent
90985048fc
commit
b6d533af4d
4 changed files with 124 additions and 8 deletions
|
@ -187,13 +187,13 @@ The ``ContentTypeManager``
|
|||
probably won't ever need to call this method yourself; Django will call
|
||||
it automatically when it's needed.
|
||||
|
||||
.. method:: get_for_model(model)
|
||||
.. method:: get_for_model(model[, for_concrete_model=True])
|
||||
|
||||
Takes either a model class or an instance of a model, and returns the
|
||||
:class:`~django.contrib.contenttypes.models.ContentType` instance
|
||||
representing that model.
|
||||
|
||||
.. method:: get_for_models(*models)
|
||||
.. method:: get_for_models(*models[, for_concrete_models=True])
|
||||
|
||||
Takes a variadic number of model classes, and returns a dictionary
|
||||
mapping the model classes to the
|
||||
|
@ -224,6 +224,19 @@ lookup::
|
|||
|
||||
.. _generic-relations:
|
||||
|
||||
.. versionadded:: 1.5
|
||||
|
||||
Prior to Django 1.5 :meth:`~ContentTypeManager.get_for_model()` and
|
||||
:meth:`~ContentTypeManager.get_for_models()` always returned the
|
||||
:class:`~django.contrib.contenttypes.models.ContentType` associated with the
|
||||
concrete model of the specified one(s). That means there was no way to retreive
|
||||
the :class:`~django.contrib.contenttypes.models.ContentType` of a proxy model
|
||||
using those methods. As of Django 1.5 you can now pass a boolean flag –
|
||||
respectively ``for_concrete_model`` and ``for_concrete_models`` – to specify
|
||||
wether or not you want to retreive the
|
||||
:class:`~django.contrib.contenttypes.models.ContentType` for the concrete or
|
||||
direct model.
|
||||
|
||||
Generic relations
|
||||
=================
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue