kopia lustrzana https://github.com/wagtail/wagtail
Moved advanced image topics into advanced topics
rodzic
ae2e73b054
commit
95ff74feeb
|
@ -0,0 +1,9 @@
|
||||||
|
Animated GIF support
|
||||||
|
====================
|
||||||
|
|
||||||
|
Pillow (Wagtail's default image library) doesn't support resizing animated
|
||||||
|
GIFs. If you need animated GIFs in your site, install
|
||||||
|
`Wand <https://pypi.python.org/pypi/Wand>`_.
|
||||||
|
|
||||||
|
When Wand is installed, Wagtail will automatically start using it for resizing
|
||||||
|
GIF files, and will continue to resize other images with Pillow.
|
|
@ -0,0 +1,82 @@
|
||||||
|
.. _custom_image_model:
|
||||||
|
|
||||||
|
Custom image models
|
||||||
|
===================
|
||||||
|
|
||||||
|
The ``Image`` model can be customised, allowing additional fields to be added
|
||||||
|
to images.
|
||||||
|
|
||||||
|
To do this, you need to add two models to your project:
|
||||||
|
|
||||||
|
- The image model itself that inherits from
|
||||||
|
``wagtail.wagtailimages.models.AbstractImage``. This is where you would add
|
||||||
|
your additional fields
|
||||||
|
- The renditions model that inherits from
|
||||||
|
``wagtail.wagtailimages.models.AbstractRendition``. This is used to store
|
||||||
|
renditions for the new model.
|
||||||
|
|
||||||
|
Here's an example:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# models.py
|
||||||
|
from django.db import models
|
||||||
|
from django.db.models.signals import pre_delete
|
||||||
|
from django.dispatch import receiver
|
||||||
|
|
||||||
|
from wagtail.wagtailimages.models import Image, AbstractImage, AbstractRendition
|
||||||
|
|
||||||
|
|
||||||
|
class CustomImage(AbstractImage):
|
||||||
|
# Add any extra fields to image here
|
||||||
|
|
||||||
|
# eg. To add a caption field:
|
||||||
|
# caption = models.CharField(max_length=255)
|
||||||
|
|
||||||
|
admin_form_fields = Image.admin_form_fields + (
|
||||||
|
# Then add the field names here to make them appear in the form:
|
||||||
|
# 'caption',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class CustomRendition(AbstractRendition):
|
||||||
|
image = models.ForeignKey(CustomImage, related_name='renditions')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = (
|
||||||
|
('image', 'filter', 'focal_point_key'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Delete the source image file when an image is deleted
|
||||||
|
@receiver(pre_delete, sender=CustomImage)
|
||||||
|
def image_delete(sender, instance, **kwargs):
|
||||||
|
instance.file.delete(False)
|
||||||
|
|
||||||
|
|
||||||
|
# Delete the rendition image file when a rendition is deleted
|
||||||
|
@receiver(pre_delete, sender=CustomRendition)
|
||||||
|
def rendition_delete(sender, instance, **kwargs):
|
||||||
|
instance.file.delete(False)
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
If you are using image feature detection, follow these instructions to
|
||||||
|
enable it on your custom image model: :ref:`feature_detection_custom_image_model`
|
||||||
|
|
||||||
|
Then set the ``WAGTAILIMAGES_IMAGE_MODEL`` setting to point to it:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
WAGTAILIMAGES_IMAGE_MODEL = 'images.CustomImage'
|
||||||
|
|
||||||
|
|
||||||
|
.. topic:: Migrating from the builtin image model
|
||||||
|
|
||||||
|
When changing an existing site to use a custom image model. No images will
|
||||||
|
be copied to the new model automatically. Copying old images to the new
|
||||||
|
model would need to be done manually with a
|
||||||
|
`data migration <https://docs.djangoproject.com/en/1.8/topics/migrations/#data-migrations>`_.
|
||||||
|
|
||||||
|
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.
|
|
@ -1,101 +1,3 @@
|
||||||
===============
|
|
||||||
Advanced topics
|
|
||||||
===============
|
|
||||||
|
|
||||||
.. _custom_image_model:
|
|
||||||
|
|
||||||
Custom image model
|
|
||||||
==================
|
|
||||||
|
|
||||||
The ``Image`` model can be customised, allowing additional fields to be added
|
|
||||||
to images.
|
|
||||||
|
|
||||||
To do this, you need to add two models to your project:
|
|
||||||
|
|
||||||
- The image model itself that inherits from
|
|
||||||
``wagtail.wagtailimages.models.AbstractImage``. This is where you would add
|
|
||||||
your additional fields
|
|
||||||
- The renditions model that inherits from
|
|
||||||
``wagtail.wagtailimages.models.AbstractRendition``. This is used to store
|
|
||||||
renditions for the new model.
|
|
||||||
|
|
||||||
Here's an example:
|
|
||||||
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
# models.py
|
|
||||||
from django.db import models
|
|
||||||
from django.db.models.signals import pre_delete
|
|
||||||
from django.dispatch import receiver
|
|
||||||
|
|
||||||
from wagtail.wagtailimages.models import Image, AbstractImage, AbstractRendition
|
|
||||||
|
|
||||||
|
|
||||||
class CustomImage(AbstractImage):
|
|
||||||
# Add any extra fields to image here
|
|
||||||
|
|
||||||
# eg. To add a caption field:
|
|
||||||
# caption = models.CharField(max_length=255)
|
|
||||||
|
|
||||||
admin_form_fields = Image.admin_form_fields + (
|
|
||||||
# Then add the field names here to make them appear in the form:
|
|
||||||
# 'caption',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class CustomRendition(AbstractRendition):
|
|
||||||
image = models.ForeignKey(CustomImage, related_name='renditions')
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
unique_together = (
|
|
||||||
('image', 'filter', 'focal_point_key'),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# Delete the source image file when an image is deleted
|
|
||||||
@receiver(pre_delete, sender=CustomImage)
|
|
||||||
def image_delete(sender, instance, **kwargs):
|
|
||||||
instance.file.delete(False)
|
|
||||||
|
|
||||||
|
|
||||||
# Delete the rendition image file when a rendition is deleted
|
|
||||||
@receiver(pre_delete, sender=CustomRendition)
|
|
||||||
def rendition_delete(sender, instance, **kwargs):
|
|
||||||
instance.file.delete(False)
|
|
||||||
|
|
||||||
.. note::
|
|
||||||
|
|
||||||
If you are using image feature detection, follow these instructions to
|
|
||||||
enable it on your custom image model: :ref:`feature_detection_custom_image_model`
|
|
||||||
|
|
||||||
Then set the ``WAGTAILIMAGES_IMAGE_MODEL`` setting to point to it:
|
|
||||||
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
WAGTAILIMAGES_IMAGE_MODEL = 'images.CustomImage'
|
|
||||||
|
|
||||||
|
|
||||||
.. topic:: Migrating from the builtin image model
|
|
||||||
|
|
||||||
When changing an existing site to use a custom image model. No images will
|
|
||||||
be copied to the new model automatically. Copying old images to the new
|
|
||||||
model would need to be done manually with a
|
|
||||||
`data migration <https://docs.djangoproject.com/en/1.8/topics/migrations/#data-migrations>`_.
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
Animated GIF support
|
|
||||||
====================
|
|
||||||
|
|
||||||
Pillow (Wagtail's default image library) doesn't support resizing animated
|
|
||||||
GIFs. If you need animated GIFs in your site, install
|
|
||||||
`Wand <https://pypi.python.org/pypi/Wand>`_.
|
|
||||||
|
|
||||||
When Wand is installed, Wagtail will automatically start using it for resizing
|
|
||||||
GIF files, and will continue to resize other images with Pillow.
|
|
||||||
|
|
||||||
|
|
||||||
.. _image_feature_detection:
|
.. _image_feature_detection:
|
||||||
|
|
||||||
Feature Detection
|
Feature Detection
|
|
@ -1,4 +1,3 @@
|
||||||
======
|
|
||||||
Images
|
Images
|
||||||
======
|
======
|
||||||
|
|
||||||
|
@ -6,7 +5,7 @@ Images
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
|
|
||||||
using_in_templates
|
animated_gifs
|
||||||
|
custom_image_model
|
||||||
|
feature_detection
|
||||||
using_images_outside_wagtail
|
using_images_outside_wagtail
|
||||||
advanced_topics
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ Advanced topics
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
|
|
||||||
|
images/index
|
||||||
settings
|
settings
|
||||||
deploying
|
deploying
|
||||||
performance
|
performance
|
||||||
|
|
|
@ -271,7 +271,7 @@ Adjust your blog page template to include the image:
|
||||||
:alt: A blog post sample
|
:alt: A blog post sample
|
||||||
|
|
||||||
You can read more about using images in templates in the
|
You can read more about using images in templates in the
|
||||||
:doc:`docs <../topics/images/index>`.
|
:doc:`docs <../topics/images>`.
|
||||||
|
|
||||||
Blog Index
|
Blog Index
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
|
|
|
@ -16,7 +16,7 @@ Below are some useful links to help you get started with Wagtail.
|
||||||
|
|
||||||
* :doc:`topics/pages`
|
* :doc:`topics/pages`
|
||||||
* :doc:`topics/writing_templates`
|
* :doc:`topics/writing_templates`
|
||||||
* :doc:`topics/images/index`
|
* :doc:`topics/images`
|
||||||
* :doc:`topics/search/index`
|
* :doc:`topics/search/index`
|
||||||
* :doc:`advanced_topics/third_party_tutorials`
|
* :doc:`advanced_topics/third_party_tutorials`
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ Usage guide
|
||||||
|
|
||||||
pages
|
pages
|
||||||
writing_templates
|
writing_templates
|
||||||
images/index
|
images
|
||||||
search/index
|
search/index
|
||||||
snippets
|
snippets
|
||||||
streamfield
|
streamfield
|
||||||
|
|
Ładowanie…
Reference in New Issue