[英]How to import django-taggit tag in django-import-export
[英]How to add translation fields in django-taggit?
好吧,當我尋找同樣的問題時,我來了:
#models.py
@register_snippet
class BlogTag(TagBase):
class Meta:
verbose_name = "tag"
verbose_name_plural = "tags"
#this is for editing in wagtail. For django not needed
panels = [
FieldPanel('name'),
FieldPanel('slug'),
]
class BlogPageTag(ItemBase):
tag = models.ForeignKey(
BlogTag, related_name="tagged_blogs", on_delete=models.CASCADE
)
content_object = ParentalKey('BlogPage', related_name='post_tags')
from modelcluster.tags import ClusterTaggableManager
class BlogPage(Page):
tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
在translation.py中:
#translation.py
from .models import BlogPage,BlogTag
from django_modeltranslation.translation import TranslationOptions,register
@register(BlogPage)
class BlogPageTR(TranslationOptions):
fields = (
'intro','body',
)
@register(BlogTag)
class BlogTagTR(TranslationOptions):
fields = (
'name',
)
我認為您必須繼承 TagBase 並添加您自己的可翻譯字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.