Docs for get_image_model/get_image_model_string

pull/3075/head
Tim Heap 2016-10-13 11:55:21 +02:00
rodzic 1b8d307316
commit b6fe08a634
2 zmienionych plików z 22 dodań i 3 usunięć

Wyświetl plik

@ -1,5 +1,6 @@
.. _custom_image_model:
===================
Custom image models
===================
@ -23,7 +24,7 @@ Here's an example:
from django.db import models
from django.db.models.signals import post_delete
from django.dispatch import receiver
from wagtail.wagtailimages.models import Image, AbstractImage, AbstractRendition
@ -87,3 +88,12 @@ Then set the ``WAGTAILIMAGES_IMAGE_MODEL`` setting to point to it:
Any templates that reference the builtin image model will still continue to
work as before but would need to be updated in order to see any new images.
Referring to the image model
============================
.. module:: wagtail.wagtailimages
.. autofunction:: get_image_model
.. autofunction:: get_image_model_string

Wyświetl plik

@ -8,12 +8,21 @@ default_app_config = 'wagtail.wagtailimages.apps.WagtailImagesAppConfig'
def get_image_model_string():
"""Get the dotted app.Model name for the image model"""
"""
Get the dotted ``app.Model`` name for the image model as a string.
Useful for developers making Wagtail plugins that need to refer to the
image model, such as in foreign keys, but the model itself is not required.
"""
return getattr(settings, 'WAGTAILIMAGES_IMAGE_MODEL', 'wagtailimages.Image')
def get_image_model():
"""Get the image model from WAGTAILIMAGES_IMAGE_MODEL."""
"""
Get the image model from the ``WAGTAILIMAGES_IMAGE_MODEL`` setting.
Useful for developers making Wagtail plugins that need the image model.
Defaults to the standard :class:`~wagtail.wagtailimages.models.Image` model
if no custom model is defined.
"""
from django.apps import apps
model_string = get_image_model_string()
try: