2016-11-03 4 views
0

アプリをインストールしたのは、pip install -e git+http://[email protected]/divio/django-polls.git#egg=pollsからです。アプリケーションは/me/env/src/polls/に保存されます。私はサーバを/me/project/から実行しています。 Poll Plugin cantをインポートできません。どのようにしてPollsアプリケーションが独自のモデルを使用するかを定義できます。アンケートからプラグインを作成する

今、テンプレートにプラグインとプレースホルダを作成します。

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

は、最初の新しいアプリを追加する必要があります。

cms.modelsから がpolls.modelsからCMSPlugin をインポートPollPluginModelを定義し、django.db輸入モデルから投票 ポーリング/モデル とリンクは投票

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 .Hereを確認してください完了ですプラグインのチュートリアル。

関連する問題