Exemplo n.º 1
0
class BlogAdmin(admin.ModelAdmin):
    fields = [
        'title', 'theme', 'category', 'topic', 'content', 'tags', 'is_draft',
        'is_published'
    ]
    list_display = [
        'title', 'theme', 'category', 'author', 'tag_display', 'created',
        'click_count', 'comment_count', 'is_draft', 'is_published'
    ]
    list_editable = ['is_draft', 'is_published']
    list_filter = ['theme__name', 'category__name', 'is_draft', 'created']
    search_fields = ['title', 'author__username']

    filter_horizontal = ['tags']

    formfield_overrides = {
        models.TextField: {
            'widget':
            UEditorWidget(width=1000,
                          file_path='downloads/',
                          image_path=settings.BLOG_IMAGE_URL,
                          scrawl_path=settings.BLOG_IMAGE_URL)
        }
    }

    def save_model(self, request, obj, form, change):
        if not change:
            obj.author = request.user
        obj.save()

    def tag_display(self, obj):
        return ', '.join([tag.name for tag in obj.tags.all()])

    tag_display.short_description = u'标签'
Exemplo n.º 2
0
 def formfield(self, **kwargs):
     defaults = {'widget': UEditorWidget(attrs=self.ueditor_settings)}
     defaults.update(kwargs)
     if defaults['widget'] == admin_widgets.AdminTextareaWidget:
         defaults['widget'] = AdminUEditorWidget(
             attrs=self.ueditor_settings)
     return super(UEditorField, self).formfield(**defaults)
Exemplo n.º 3
0
 class Meta:
     model = Inter
     widgets = {
         'abstract':
         forms.Textarea,
         'content':
         UEditorWidget(width=1000,
                       file_path='/downloads/',
                       image_path=settings.INTER_UPLOADED_IMAGE_URL,
                       scrawl_path=settings.INTER_UPLOADED_IMAGE_URL)
     }
Exemplo n.º 4
0
    def __init__(self,
                 label,
                 width=600,
                 height=400,
                 toolbars="full",
                 image_path="",
                 file_path="",
                 upload_settings=None,
                 settings=None,
                 command=None,
                 event_handler=None,
                 *args,
                 **kwargs):
        if upload_settings is None:
            upload_settings = {}
        if settings is None:
            settings = {}

        ueditor_settings = locals().copy()
        del ueditor_settings["self"], ueditor_settings[
            "label"], ueditor_settings["args"], ueditor_settings["kwargs"]
        kwargs["widget"] = UEditorWidget(attrs=ueditor_settings)
        kwargs["label"] = label
        super(UEditorField, self).__init__(*args, **kwargs)