Created
August 9, 2013 10:16
-
-
Save guillaumepiot/6192618 to your computer and use it in GitHub Desktop.
CMSBase - Testimonials admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from django import forms | |
from django.utils.translation import ugettext_lazy as _ | |
from mptt.forms import TreeNodeMultipleChoiceField | |
from cmsbase.models import Page | |
from hollyfield.models import Testimonial | |
class TestimonialForm(forms.ModelForm): | |
related_to = TreeNodeMultipleChoiceField(queryset=Page.objects.get_published_original(), help_text=_('Publish this testimonial on the selected pages'), required=False, widget=forms.CheckboxSelectMultiple) | |
class Meta: | |
model = Testimonial | |
fields = ['content', 'author', 'publish', 'related_to'] | |
class TestimonialAdmin(admin.ModelAdmin): | |
form = TestimonialForm | |
list_display = ['content', 'author', 'publish', 'related_pages', 'action'] | |
list_display_links = ('action',) | |
def action(self, obj): | |
return _('Update') | |
action.allow_tags = True | |
action.short_description = 'Action' | |
def related_pages(self, obj): | |
if obj.related_to: | |
page_list = [page.translated().title for page in obj.related_to.all()] | |
return ",".join(page_list) | |
else: | |
return '' | |
related_pages.allow_tags = True | |
related_pages.short_description = 'Related to' | |
admin.site.register(Testimonial, TestimonialAdmin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment