问题描述
我正在使用带有一些自定义App钩子的Django cms。英文一切正常。现在我需要阿拉伯文的应用程序。但是,当我更改阿拉伯语的内容时,英语页面上也会反映出同样的内容。怎么处理。
我对Django cms非常陌生。请帮忙。
应用挂钩模型
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,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'),]
cms_plugins
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,placeholder):
selected_services = instance.featured_services.all()
context.update({'instance': instance})
context["selected_services"] = selected_services
return context
cms_apps
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"]
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)