djangocms自定义多语言apphook
我正在使用Django cms与一些自定义应用程序挂钩的模型。对于英语来说,一切都很顺利。现在我需要阿拉伯语的应用程序。但当我把内容改成阿拉伯语时,同样的内容也会反映在英语页面上。如何处理同样的问题 我对Django cms很陌生。请帮忙 应用程序挂钩模式djangocms自定义多语言apphook,django,multilingual,django-cms,Django,Multilingual,Django Cms,我正在使用Django cms与一些自定义应用程序挂钩的模型。对于英语来说,一切都很顺利。现在我需要阿拉伯语的应用程序。但当我把内容改成阿拉伯语时,同样的内容也会反映在英语页面上。如何处理同样的问题 我对Django cms很陌生。请帮忙 应用程序挂钩模式 from django.db import models from filer.fields.image import FilerImageField from django.urls import reverse from cms.mode
from django.db import models
from filer.fields.image import FilerImageField
from django.urls import reverse
from cms.models.fields import PlaceholderField
from cms.models import CMSPlugin
from djangocms_text_ckeditor.fields import HTMLField
# Create your models here.
class Services(models.Model):
class Meta:
app_label= 'voxservices'
service_name = models.CharField(
blank=False,
unique=True,
help_text="Please enter the Service you are providing",
max_length=100
)
slug = models.SlugField(
blank=False,
default='',
help_text='Provide a unique slug for this service',
max_length=100,
)
photo = FilerImageField(
blank=True,
null=True,
on_delete=models.SET_NULL,
help_text='Add the photo for the service'
)
font_awesome_class = models.CharField(
max_length=100,
null=True,
blank=True
)
service_intro = models.TextField()
service_description = HTMLField(blank=True)
is_featured = models.BooleanField()
def get_absolute_url(self):
return reverse("voxservices:services_detail", kwargs={"slug": self.slug})
def __str__(self):
return self.service_name
# For plugin
class FeaturedServicesPluginModel(CMSPlugin):
featured_services = Services.objects.all().filter(is_featured=True)
def __str__(self):
return "{selected} Selected articles".format(selected=self.featured_services.all())
def copy_relations(self, oldinstance):
self.featured_services = oldinstance.featured_services.all()
视图
from django.shortcuts import render
from django.views.generic import DetailView,ListView
from .models import Services
# Create your views here.
class ServicesListView(ListView):
model = Services
queryset = Services.objects.order_by().all()
class ServicesDetailView(DetailView):
model = Services
context_object_name = 'service'
def get_context_data(self, *args, **kwargs):
context = super(ServicesDetailView, self).get_context_data(*args, **kwargs)
context['service_list'] = Services.objects.all()
return context
from django.urls import path,include,re_path
from .views import ServicesDetailView,ServicesListView
urlpatterns = [
path('',ServicesListView.as_view(),name="services_list"),
re_path(r'^(?P<slug>[^/]+)/$', ServicesDetailView.as_view(), name='services_detail'),
]
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
# from .models import PollPluginModel
from .models import FeaturedServicesPluginModel
from django.utils.translation import ugettext as _
@plugin_pool.register_plugin # register the plugin
class FeaturedServicesPluginPublisher(CMSPluginBase):
model = FeaturedServicesPluginModel # model where plugin data are saved
module = _("Services")
name = _("FeaturedServices Plugin") # name of the plugin in the interface
render_template = "voxservices/services_plugin.html"
def render(self, context, instance, placeholder):
selected_services = instance.featured_services.all()
context.update({'instance': instance})
context["selected_services"] = selected_services
return context
@plugin_pool.register_plugin # register the plugin
class FeaturedServicesFooterPluginPublisher(CMSPluginBase):
model = FeaturedServicesPluginModel # model where plugin data are saved
module = _("Services")
name = _("FeaturedServices Footer Plugin") # name of the plugin in the interface
render_template = "voxservices/services_footer_plugin.html"
def render(self, context, instance, placeholder):
selected_services = instance.featured_services.all()
context.update({'instance': instance})
context["selected_services"] = selected_services
return context
from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import ugettext_lazy as _
from .menu import ServicesSubMenu
@apphook_pool.register
class ServicesApp(CMSApp):
name = _('VOXServices')
# urls = ['voxservices.urls', ]
app_name = 'voxservices'
menus = [ServicesSubMenu, ]
def get_urls(self, page=None, language=None, **kwargs):
return ["voxservices.urls"]
URL
from django.shortcuts import render
from django.views.generic import DetailView,ListView
from .models import Services
# Create your views here.
class ServicesListView(ListView):
model = Services
queryset = Services.objects.order_by().all()
class ServicesDetailView(DetailView):
model = Services
context_object_name = 'service'
def get_context_data(self, *args, **kwargs):
context = super(ServicesDetailView, self).get_context_data(*args, **kwargs)
context['service_list'] = Services.objects.all()
return context
from django.urls import path,include,re_path
from .views import ServicesDetailView,ServicesListView
urlpatterns = [
path('',ServicesListView.as_view(),name="services_list"),
re_path(r'^(?P<slug>[^/]+)/$', ServicesDetailView.as_view(), name='services_detail'),
]
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
# from .models import PollPluginModel
from .models import FeaturedServicesPluginModel
from django.utils.translation import ugettext as _
@plugin_pool.register_plugin # register the plugin
class FeaturedServicesPluginPublisher(CMSPluginBase):
model = FeaturedServicesPluginModel # model where plugin data are saved
module = _("Services")
name = _("FeaturedServices Plugin") # name of the plugin in the interface
render_template = "voxservices/services_plugin.html"
def render(self, context, instance, placeholder):
selected_services = instance.featured_services.all()
context.update({'instance': instance})
context["selected_services"] = selected_services
return context
@plugin_pool.register_plugin # register the plugin
class FeaturedServicesFooterPluginPublisher(CMSPluginBase):
model = FeaturedServicesPluginModel # model where plugin data are saved
module = _("Services")
name = _("FeaturedServices Footer Plugin") # name of the plugin in the interface
render_template = "voxservices/services_footer_plugin.html"
def render(self, context, instance, placeholder):
selected_services = instance.featured_services.all()
context.update({'instance': instance})
context["selected_services"] = selected_services
return context
from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import ugettext_lazy as _
from .menu import ServicesSubMenu
@apphook_pool.register
class ServicesApp(CMSApp):
name = _('VOXServices')
# urls = ['voxservices.urls', ]
app_name = 'voxservices'
menus = [ServicesSubMenu, ]
def get_urls(self, page=None, language=None, **kwargs):
return ["voxservices.urls"]
cms\u应用程序
from django.shortcuts import render
from django.views.generic import DetailView,ListView
from .models import Services
# Create your views here.
class ServicesListView(ListView):
model = Services
queryset = Services.objects.order_by().all()
class ServicesDetailView(DetailView):
model = Services
context_object_name = 'service'
def get_context_data(self, *args, **kwargs):
context = super(ServicesDetailView, self).get_context_data(*args, **kwargs)
context['service_list'] = Services.objects.all()
return context
from django.urls import path,include,re_path
from .views import ServicesDetailView,ServicesListView
urlpatterns = [
path('',ServicesListView.as_view(),name="services_list"),
re_path(r'^(?P<slug>[^/]+)/$', ServicesDetailView.as_view(), name='services_detail'),
]
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
# from .models import PollPluginModel
from .models import FeaturedServicesPluginModel
from django.utils.translation import ugettext as _
@plugin_pool.register_plugin # register the plugin
class FeaturedServicesPluginPublisher(CMSPluginBase):
model = FeaturedServicesPluginModel # model where plugin data are saved
module = _("Services")
name = _("FeaturedServices Plugin") # name of the plugin in the interface
render_template = "voxservices/services_plugin.html"
def render(self, context, instance, placeholder):
selected_services = instance.featured_services.all()
context.update({'instance': instance})
context["selected_services"] = selected_services
return context
@plugin_pool.register_plugin # register the plugin
class FeaturedServicesFooterPluginPublisher(CMSPluginBase):
model = FeaturedServicesPluginModel # model where plugin data are saved
module = _("Services")
name = _("FeaturedServices Footer Plugin") # name of the plugin in the interface
render_template = "voxservices/services_footer_plugin.html"
def render(self, context, instance, placeholder):
selected_services = instance.featured_services.all()
context.update({'instance': instance})
context["selected_services"] = selected_services
return context
from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import ugettext_lazy as _
from .menu import ServicesSubMenu
@apphook_pool.register
class ServicesApp(CMSApp):
name = _('VOXServices')
# urls = ['voxservices.urls', ]
app_name = 'voxservices'
menus = [ServicesSubMenu, ]
def get_urls(self, page=None, language=None, **kwargs):
return ["voxservices.urls"]
恐怕翻译需要一种不同的方法。我可以在这里分享一个博客应用的例子-