2016-11-03 14 views
0

Я установил приложение Опросы с pip install -e git+http://[email protected]/divio/django-polls.git#egg=polls от. Приложение сохраняется /me/env/src/polls/. Я запускаю сервер от /me/project/. Я получаю сообщение об ошибке. Как я могу определить, что приложение «Опросы» использует собственные модели.создать плагин из опросов aplication

Теперь я хочу создать плагин и заполнитель в моем шаблоне.

cms_plugins.py 

    from cms.plugin_base import CMSPluginBase 
    from cms.plugin_pool import plugin_pool 
    from polls.models import PollPlugin as PollPluginModel 
    from django.utils.translation import ugettext as _ 

    class PollPlugin(CMSPluginBase): 
     model = PollPluginModel # <--not sure what to put here. 
     name = _("Poll Plugin") # Name of the plugin 
     render_template = "polls/plugin.html" # 

     def render(self, context, instance, placeholder): 
      context.update({'instance':instance}) 
      return context 

    plugin_pool.register_plugin(PollPlugin) # register the plugin 

опросы/models.py

class Poll(models.Model): 
     question = models.CharField(max_length=200) 

     def __unicode__(self): # Python 3: def __str__(self): 
      return self.question 


class Choice(models.Model): 
    poll = models.ForeignKey(Poll) 
    choice_text = models.CharField(max_length=200) 
    votes = models.IntegerField(default=0) 

    def __unicode__(self): # Python 3: def __str__(self): 
     return self.choice_text 

ответ

0

сначала вам нужно добавить новое приложение.

Определить PollPluginModel и связать его с опроса опросы/модели от импортных моделей django.db из cms.models импорта CMSPlugin из polls.models импорта Poll

class PollPluginModel(CMSPlugin): 
    poll = models.ForeignKey(Poll) 

    def __unicode__(self): 
     return self.poll.question 

Пожалуйста, проверьте http://docs.django-cms.org/en/release-3.4.x/introduction/plugins.html .Здесь завершена учебник для плагина.