kopia lustrzana https://github.com/wagtail/wagtail
Docs for get_image_model/get_image_model_string
rodzic
1b8d307316
commit
b6fe08a634
|
|
@ -1,5 +1,6 @@
|
||||||
.. _custom_image_model:
|
.. _custom_image_model:
|
||||||
|
|
||||||
|
===================
|
||||||
Custom image models
|
Custom image models
|
||||||
===================
|
===================
|
||||||
|
|
||||||
|
|
@ -23,7 +24,7 @@ Here's an example:
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models.signals import post_delete
|
from django.db.models.signals import post_delete
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
|
||||||
from wagtail.wagtailimages.models import Image, AbstractImage, AbstractRendition
|
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
|
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.
|
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
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,21 @@ default_app_config = 'wagtail.wagtailimages.apps.WagtailImagesAppConfig'
|
||||||
|
|
||||||
|
|
||||||
def get_image_model_string():
|
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')
|
return getattr(settings, 'WAGTAILIMAGES_IMAGE_MODEL', 'wagtailimages.Image')
|
||||||
|
|
||||||
|
|
||||||
def get_image_model():
|
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
|
from django.apps import apps
|
||||||
model_string = get_image_model_string()
|
model_string = get_image_model_string()
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue