Skip to content

Instantly share code, notes, and snippets.

@g3rd
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g3rd/3442580966f8a12035b2 to your computer and use it in GitHub Desktop.
Save g3rd/3442580966f8a12035b2 to your computer and use it in GitHub Desktop.
CMS Plugin w/Site support

Is this the best approach to getting site specific data with a Django CMS plugin?

I've added a site reference to the model and switched the default model manager to the CurrentSiteManager.

So that in forms.py on line 7. When I get the data, I'm only getting data for the current site.

Thoughts?

See:

https://plus.google.com/103026533969319599841/posts/4GghcierP1N

For the conversation and best approach.

class MoodPlugin(CMSPluginBase):
allow_children = False
cache = True
model = Mood
name = _('Mood')
render_template = 'cmsplugin_moods/mood.html'
text_enabled = False
form = MoodForm
plugin_pool.register_plugin(MoodPlugin)
class MoodForm(forms.ModelForm):
Meta = select2_modelform_meta(SocialLink)
def __init__(self, *args, **kwargs):
super(MoodForm, self).__init__(*args, **kwargs)
mood_data = Mood.objects.values_list('mood', flat=True).order_by('mood')
self.fields['mood'].widget = Select2TextInput(select2attrs={
'data': [{'id': x, 'text': x} for x in mood_data]
})
class Mood(CMSPlugin):
taints_cache = True
site = models.ForeignKey(Site)
mood = models.CharField(_('mood'), max_length=25, default="", help_text=_('What is your mood?'))
objects = CurrentSiteManager()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment