我想在customized admin form中获得当前页面的祖先页面:
# models.py
class TopicPage(Page):
def get_topic_path(self):
return (
self
.get_ancestors(inclusive=True)
.filter(depth__gt=3)
.values_list('title', flat=True)
)
base_form_class = TopicPageForm
# forms.py
class TopicPageForm(WagtailAdminPageForm):
def save(self, commit=True):
page = super().save(commit=False)
page.get_topic_path()
if commit:
page.save()
return page
但是对于新的TopicPage
实例,get_ancestors
在保存页面之前不会返回任何内容:
TopicPage
对象get_ancestors
返回空查询集get_ancestors
返回预期的查询集即使对于新的(未保存的)页面,我如何也可以通过WagtailAdminPageForm
save()方法获取当前页面的祖先页面?
答案 0 :(得分:0)
通过Wagtail的页面添加/编辑视图实例化XxxxCloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Aliases:
- ${self:provider.environment.CUSTOM_DOMAIN}
Origins:
- DomainName: ${self:provider.environment.BUCKET_NAME}.s3-website-us-east-1.amazonaws.com
Id: Xxxx
CustomOriginConfig:
HTTPPort: 80
OriginProtocolPolicy: http-only
Enabled: 'true'
DefaultRootObject: index.html
CustomErrorResponses:
- ErrorCode: 404
ResponseCode: 200
ResponsePagePath: /error.html
DefaultCacheBehavior:
AllowedMethods:
- DELETE
- GET
- HEAD
- OPTIONS
- PATCH
- POST
- PUT
TargetOriginId: Xxxx
Compress: 'true'
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
ViewerProtocolPolicy: redirect-to-https
ViewerCertificate:
AcmCertificateArn: ${self:provider.environment.ACM_CERT_ARN}
SslSupportMethod: sni-only
时,它将传递给父页面;然后可以在表单对象上以WagtailAdminPageForm
的形式使用它。 Wagtail使用此方法来验证页面信息的唯一性,但是您也可以在自定义self.parent_page
方法中使用它-在这种情况下,您可以通过在父方法上调用save
来复制get_topic_path
页,并将.get_ancestors(inclusive=True)
附加到结果。