2016-04-04 10 views
0

とクエリセットのPython 3使用related_nameジャンゴCMSプラグイン

Djangoの1.9

ジャンゴ-CMS 3.2.2

私はこのようなものがあります:

models.py

class PluginModel(CMSPlugin): 
    title = models.CharField(max_length=60) 

class InlineModel(models.Model): 
    title = models.CharField(max_length=60) 
    plugin_key = models.ForeignKey('PluginModel' related_name='breakpoints') 

cms_plugins.py

class InlineModelInline(admin.StackedInline): 
    model = InlineModel 

class PluginModelPlugin(CMSPluginBase): 
    model = PluginModel 
    inlines = [InlineModelInline,] 

    def render(self, context, instance, placeholder): 
     context = super(CarouselPlugin, self).render(context, instance, placeholder) 
     print(instance.breakpoints.all()) #for simple debug 

私はいくつかのインラインを追加して保存します。編集では、すべてのインラインが正常に表示されますが、ページを公開すると、空のリストだけが返されます。私は出版システムの欠陥であることを理解していますが、どうすればそれを動作させることができますか?

+0

'context = super(CarouselPlugin、self)'は正しいですか? –

+0

これは面白いことですが、私はドキュメンテーションを読んで、これが本当であり、偶然あなたの質問に対応していることを示しています。 – Atterratio

答えて

1

何かこれはうまくいくはずです。 @ atterratioの答えは多対多の関係のためだけに機能します:

class PluginModel(CMSPlugin): 
    title = models.CharField(max_length=60) 

    def copy_relations(self, oldinstance): 
     for breakpoint in oldinstance.breakpoints.all(): 
      breakpoint.pk = None 
      breakpoint.plugin_key = self 
      breakpoint.save() 
+0

私はForeginKeyを使っていますが、このコードはドキュメントではなく、私の仕事ですが、私の仕事です。 Djangoのいくつかの変更があります、私は最新のものを使用していますか? – Atterratio

+0

M2MまたはFKの関係を使用しているかどうかに基づいて実装に違いがあります。あなたの質問では、FKを使用しているので、私が投稿したスニペットはうまくいくはずです。 – mishbah

+0

私はFKを使用してUに、Uコードは私の仕事では機能しません。 – Atterratio

関連する問題