一个用于创建带有注释元数据的图片字段的Wagtail模块
项目描述
允许用户将自定义注释数据与Wagtail图片结合。通过在图像上点击点来输入注释,然后注释数据将与相对的x,y坐标和可选的额外表单数据一起存储。
要求
Wagtail >= 2.7
Django >= 2.0
安装
使用pypi安装
pip install wagtailannotatedimage
使用
扩展BaseAnnotationForm以定义应该与注释一起存储哪些数据。AnnotationsField将注释数据存储为json,在检索时转换为字典。
from django import forms
from django.db import models
from wagtail.wagtailcore.models import Page
from wagtailannotatedimage.edit_handlers import AnnotatedImagePanel
from wagtailannotatedimage.fields import AnnotationsField
from wagtailannotatedimage.forms import BaseAnnotationForm
class AnnotationForm(BaseAnnotationForm):
title = forms.CharField()
about = forms.TextField()
class TestPage(Page):
image = models.ForeignKey('wagtailimages.Image', blank=True, null=True,
on_delete=models.SET_NULL, related_name="+")
annotations = AnnotationsField(blank=True)
content_panels = Page.content_panels + [
# First parameter - name of the image field
# Second parameter - name of the annotation field
# annotation_form - optional, the form used for annotations if you need to store data for each point
AnnotatedImagePanel(
'image', 'annotations',
annotation_form=AnnotationForm(), heading='Annotated Image'
)
]
<div class='image-container'>
{% image page.image('width-500') %}
{% for annotation in page.annotations %}
<div
class='annotation'
style="left: {{ annotation.x * 100 }}%; top: {{ annotation.y * 100 }}%;"
>
<h3>{{ annotation.fields.title }}</h3>
<p>{{ annotation.fields.about }}</p>
</div>
{% endfor %}
</div>
.image-container {
position: relative;
}
.image-container > img {
width: 100%;
height: auto;
}
.annotation {
position: absolute;
}
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分布
wagtailannotatedimage-2.7.0.tar.gz (10.8 kB 查看哈希值)
构建分布
关闭
wagtailannotatedimage-2.7.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 55f8d49e06456a8f8b8be19647a7c26c680558b9c5195f0ff471cf1614eaaa9d |
|
MD5 | 26071719072848dea0de6b7fbb74cdb7 |
|
BLAKE2b-256 | 9a69e932760e5501bd202270fc3d101722f2f8ccc94c356fc6b9e135e919506a |
关闭
wagtailannotatedimage-2.7.0-py2.py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3c3e98406dc0f1c4a48cb26ddf7528c6ff51bd1b991dcf7a1dd8a648b8d7bd28 |
|
MD5 | 29aac3c245239c8806037c56873bfa01 |
|
BLAKE2b-256 | 51b690da9111e0eeaa94ab0713cbc5eb3b9ac5b625b487d673d108c2c83b1443 |