我创建了自定义事件插件,现在我想在我的主页上显示最接近的事件(带有home.html模板的django-cms页面)。 我该怎么做?这是我的事件/ models.py
from django.core.urlresolvers import reverse
from django.db import models
from adminsortable.models import Sortable
from easy_thumbnails.fields import ThumbnailerImageField
from cms.models.fields import PlaceholderField
from cms.models.pluginmodel import CMSPlugin
class Event(Sortable):
class Meta:
app_label = 'event'
event_name = models.CharField(
blank=False,
default='',
max_length=64,
)
date = models.DateField(
auto_now=False,
auto_now_add=False,
)
photo = ThumbnailerImageField(
upload_to='events',
blank=True,
)
def __unicode__(self):
return self.event_name
答案 0 :(得分:1)
要获取最新活动,您可以覆盖插件的render
方法:
class YourCMSPlugIn(CMSPluginBase):
model = Event
...
def render(self, context, instance, placeholder):
context.update({
'latest_event': self.model.objects.all()[:1],
'placeholder': placeholder
})
return context
有关详细信息,请参阅:http://docs.django-cms.org/en/latest/extending_cms/custom_plugins.html#storing-configuration。