Wagtail 图片上传:如何设置图片存储位置?
Wagtail image upload : how to set where the image is stored?
我发现了鹡鸰。当我创建 post 时,我可以上传图片,但它们存储在我的 webapp 的目录 /media 中。
我想将它们存储在 s3 存储桶或 wagtail 数据库中。
这是我的 models.py:
from django.db import models
from wagtail.core.models import Page
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.snippets.models import register_snippet
from taggit.models import Tag as TaggitTag
from modelcluster.fields import ParentalKey
from taggit.models import TaggedItemBase
from modelcluster.tags import ClusterTaggableManager
from wagtail.admin.edit_handlers import (FieldPanel,
FieldRowPanel,
InlinePanel,
MultiFieldPanel,
PageChooserPanel,
StreamFieldPanel,
)
from wagtail.snippets.edit_handlers import SnippetChooserPanel
from wagtail.core.fields import StreamField
from .blocks import BodyBlock
class BlogPage(Page):
description = models.CharField(max_length=255, blank=True,)
content_panels = Page.content_panels + [FieldPanel("description", classname="full")]
class PostPage(Page):
header_image = models.ForeignKey(
"wagtailimages.Image", null=True,
blank=True, on_delete=models.SET_NULL, related_name="+",)
body = StreamField(BodyBlock(), blank=True)
tags = ClusterTaggableManager(through="blog.PostPageTag", blank=True)
content_panels = Page.content_panels + [ ImageChooserPanel("header_image"), InlinePanel("categories", label="category"), FieldPanel("tags"),StreamFieldPanel("body"),]
@register_snippet
class BlogCategory(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField(unique=True, max_length=80)
panels = [ FieldPanel("name"),
FieldPanel("slug"),]
def __str__(self):
return self.name
class Meta:
verbose_name = "Category"
verbose_name_plural = "Categories"
@register_snippet
class Tag(TaggitTag):
class Meta:
proxy = True
class PostPageBlogCategory(models.Model):
page = ParentalKey("blog.PostPage", on_delete=models.CASCADE, related_name="categories" )
blog_category = models.ForeignKey("blog.BlogCategory", on_delete=models.CASCADE, related_name="post_pages")
panels = [ SnippetChooserPanel("blog_category"),]
class Meta:
unique_together = ("page", "blog_category")
class PostPageTag(TaggedItemBase):
content_object = ParentalKey("PostPage", related_name="post_tags")
在我的 settings.py 我还有:
MEDIA_ROOT = str(BASE_DIR / 'media')
MEDIA_URL = '/media/'
与我的网络应用程序中的媒体文件夹相对应。我想我可以对此进行调整,但如何将所有 s3 授权放到位?
您可能会发现 django-storages 可以满足您的需求。
有一个 Amazon S3 部分介绍了设置过程。
我发现了鹡鸰。当我创建 post 时,我可以上传图片,但它们存储在我的 webapp 的目录 /media 中。
我想将它们存储在 s3 存储桶或 wagtail 数据库中。
这是我的 models.py:
from django.db import models
from wagtail.core.models import Page
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.snippets.models import register_snippet
from taggit.models import Tag as TaggitTag
from modelcluster.fields import ParentalKey
from taggit.models import TaggedItemBase
from modelcluster.tags import ClusterTaggableManager
from wagtail.admin.edit_handlers import (FieldPanel,
FieldRowPanel,
InlinePanel,
MultiFieldPanel,
PageChooserPanel,
StreamFieldPanel,
)
from wagtail.snippets.edit_handlers import SnippetChooserPanel
from wagtail.core.fields import StreamField
from .blocks import BodyBlock
class BlogPage(Page):
description = models.CharField(max_length=255, blank=True,)
content_panels = Page.content_panels + [FieldPanel("description", classname="full")]
class PostPage(Page):
header_image = models.ForeignKey(
"wagtailimages.Image", null=True,
blank=True, on_delete=models.SET_NULL, related_name="+",)
body = StreamField(BodyBlock(), blank=True)
tags = ClusterTaggableManager(through="blog.PostPageTag", blank=True)
content_panels = Page.content_panels + [ ImageChooserPanel("header_image"), InlinePanel("categories", label="category"), FieldPanel("tags"),StreamFieldPanel("body"),]
@register_snippet
class BlogCategory(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField(unique=True, max_length=80)
panels = [ FieldPanel("name"),
FieldPanel("slug"),]
def __str__(self):
return self.name
class Meta:
verbose_name = "Category"
verbose_name_plural = "Categories"
@register_snippet
class Tag(TaggitTag):
class Meta:
proxy = True
class PostPageBlogCategory(models.Model):
page = ParentalKey("blog.PostPage", on_delete=models.CASCADE, related_name="categories" )
blog_category = models.ForeignKey("blog.BlogCategory", on_delete=models.CASCADE, related_name="post_pages")
panels = [ SnippetChooserPanel("blog_category"),]
class Meta:
unique_together = ("page", "blog_category")
class PostPageTag(TaggedItemBase):
content_object = ParentalKey("PostPage", related_name="post_tags")
在我的 settings.py 我还有:
MEDIA_ROOT = str(BASE_DIR / 'media')
MEDIA_URL = '/media/'
与我的网络应用程序中的媒体文件夹相对应。我想我可以对此进行调整,但如何将所有 s3 授权放到位?
您可能会发现 django-storages 可以满足您的需求。
有一个 Amazon S3 部分介绍了设置过程。