Django: What is an awesome admin image support plugin?

I have a model for entering articles, and I have an excerpt and description field. If the user wants to send an image, then I have a separate ImageField, which has a default default file browser.

I tried using django-filebrowser , but I don’t like the fact that it requires django-grappelli and I don’t necessarily need a utility to load flash memory. Can anyone recommend a tool in which I can control image loading and basically replace the file view provided by django using the image browser?

In the future, I probably want it to handle image size and determine default image sizes for certain types of articles.

Edit: Now I'm trying adminfiles , but I am having problems installing it. I grabbed it and added python to my path, added it to INSTALLED_APPS, created databases for it, uploaded the image. I followed the instructions to modify my model to specify adminfiles_fields and registered, but was not used in my admin, here is my admin.py for articles:

 from django.contrib import admin from django import forms from articles.models import Category, Entry from tinymce.widgets import TinyMCE from adminfiles.admin import FilePickerAdmin class EntryForm( forms.ModelForm ): class Media: js = ['/media/tinymce/tiny_mce.js', '/media/tinymce/load.js']#, '/media/admin/filebrowser/js/TinyMCEAdmin.js'] class Meta: model = Entry class CategoryAdmin(admin.ModelAdmin): prepopulated_fields = { 'slug': ['title'] } class EntryAdmin( FilePickerAdmin ): adminfiles_fields = ('excerpt',) prepopulated_fields = { 'slug': ['title'] } form = EntryForm admin.site.register( Category, CategoryAdmin ) admin.site.register( Entry, EntryAdmin ) 

Here is my input model:

 class Entry( models.Model ): LIVE_STATUS = 1 DRAFT_STATUS = 2 HIDDEN_STATUS = 3 STATUS_CHOICES = ( ( LIVE_STATUS, 'Live' ), ( DRAFT_STATUS, 'Draft' ), ( HIDDEN_STATUS, 'Hidden' ), ) status = models.IntegerField( choices=STATUS_CHOICES, default=LIVE_STATUS ) tags = TagField() categories = models.ManyToManyField( Category ) title = models.CharField( max_length=250 ) excerpt = models.TextField( blank=True ) excerpt_html = models.TextField(editable=False, blank=True) body_html = models.TextField( editable=False, blank=True ) article_image = models.ImageField(blank=True, upload_to='upload') body = models.TextField() enable_comments = models.BooleanField(default=True) pub_date = models.DateTimeField(default=datetime.datetime.now) slug = models.SlugField(unique_for_date='pub_date') author = models.ForeignKey(User) featured = models.BooleanField(default=False) def save( self, force_insert=False, force_update= False): self.body_html = markdown(self.body) if self.excerpt: self.excerpt_html = markdown( self.excerpt ) super( Entry, self ).save( force_insert, force_update ) class Meta: ordering = ['-pub_date'] verbose_name_plural = "Entries" def __unicode__(self): return self.title 

Edit # 2: To clarify that I moved the media files to my media path, and they really display the image area, I can upload the text, the << <<<image>>> tag is inserted into my editable MarkItUp w / Markdown area, but it doesn’t appears in the preview of MarkItUp - maybe I just need to apply |upload_tags for this preview. I will try to add it to my template, which will also post the article.

+4
source share
2 answers

Try django-adminfiles - it's awesome. You can upload images or select existing ones and paste them anywhere in the text where they will be displayed as <<<placeholders>>> . You have complete control over how placement placeholders are allowed on the actual site using special templates - allowing you to control how images are displayed on the site (including scaling, using, for example, the sorl.thumbnail template tag).

An application can easily support the insertion of other types of files - you simply create templates for a specific type of file, showing how it should be presented on your website. It even supports pasting from Flicker and YouTube.

As you can see, I'm still very happy to find it :)

It will look something like this in the admin panel (although the screenshot is from a really old version):

django-adminfiles http://lincolnloop.com/legacy/media/img/django-admin-uploads.png

Update . You have complete control over when and how images are displayed. Some examples:

  • For the main page of the article, I need a default image display style, so what I write in my template (this will display images according to the rules defined in my adminfiles / render / image / default.html file by default template):

    {{ article.content|render_uploads }}

  • But let me say that in my email newsletter I don’t want to insert an image - I just want to link it. I will write this in the template (this will display the images according to the rules defined in the adminfiles / render_as_link / default.html template):

    {{ post.content|render_uploads:"adminfiles/render_as_link" }}

  • I don’t want to have code to insert images (or any other HTML code) in my search index, so in my django-haystack template I just do this to remove all the HTML:

    {{ article.content|render_uploads|striptags }}

  • Or I can do this to index the captions of images (but not the images themselves, again, this assumes you have the adminfiles / only_caption / default.html template with the correct code):

    {{ article.content|render_uploads:"adminfiles/only_caption" }}

  • Ok, but what if I want to keep all the rest of the HTML formatting but don't want to display the images? I will create an empty adminfiles/blank/default.html file and to this:

    {{ article.content|render_uploads:"adminfiles/blank" }}

There are other ways to achieve the same effect (for example, by choosing the rights ADMINFILES_REF_START and ADMINFILES_REF_END and not using the filter at all), but I think this post is too long;)

+9
source

Grappelli is optional for using django-filebrowser. I use this implementation in almost all of my projects: https://github.com/wardi/django-filebrowser-no-grappelli

Happy coding!

+1
source

Source: https://habr.com/ru/post/1300567/


All Articles