Some usefull hacks based on sorl-thumbnail
Project description
create_thumbs template tag
Parse your text on fly, finds images urls and replace it by thumb url:
{% load sorl_hacks %} {% for text_block in post.blocks.all %} <h4>{{ text_block }}</h4> <p>{{ text_block.body|create_thumbs|safe }}</p> <hr> {% endfor %}
ThumbedCkeditorImages
Admin model mixin with post_save replacing.
admin.py:
from sorl_hacks.admin import ThumbedCkeditorImages
class BlogPostAdmin(ThumbedCkeditorImages):
...
ThumbMixin
Usefull in stadart Django templates. Add property my_model.get_thumb_WIDTHxHEIGHT to yours models.
Example of my_model_detail.html:
{{ my_model.get_thumb_200x200.html }} {{ my_model.get_thumb_small.html }}
instead of:
{% thumbnail my_model.pic "56x56" crop="center" as im %} <img src="{{ im.url }}" width="56" height="56"> {% empty %} <img src="{{ MISSING_IMAGE }}" width="56" height="56"> {% endthumbnail %}
INSTALL
Your models.py:
from django.db import models
from sorl.thumbnail import ImageField
from sorl_hacks.models import ThumbMixin
class Post(ThumbMixin, models.Model):
image = ImageField('image', upload_to='posts', **nullable)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-sorl-hacks-0.1.10.tar.gz
.
File metadata
- Download URL: django-sorl-hacks-0.1.10.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 760b6a6e897b37bd44c8abe6de2bf1adc27fd29d4bfed1cc385593fa895c155e |
|
MD5 | cfc779030ba358427ed912a6c1381303 |
|
BLAKE2b-256 | 94000b79fa00dca97113f7b6bfb4be0d25aab192507f0650f9be2c6af3b28633 |