Skip to main content

Django field for create snippet image for sharing in social networks.

Project description

The python package provides a django field for automatic generation of images for sharing in social networks.

django-snippet-image based on snippet-image package.


` pip3 install django-snippet-image `


Use SnippetImageField:

from django.db.models import (
from django_snippet_image import SnippetImageField

class Statuses:
    DRAFT = 'draft'
    PUBLISH = 'publish'

    CHOICES = (
        (DRAFT, 'Draft'),
        (PUBLISH, 'Publish'),

class ExampleModel(Model):
    text = CharField(
        verbose_name='Text for snippet image',
    background = ImageField(
        verbose_name='Background for snippet image',
    snippet_image_field = SnippetImageField(
        verbose_name='Example snippet image field',
    status = CharField(

    # Methods for collect data for snippet image.

    def get_snippet_image_text(self, snippet_type):
        return self.text if snippet_type == 'default' and self.text else ''

    def get_snippet_image_background(self, snippet_type):
        if snippet_type == 'default' and self.background:
            return self.background.path

    def snippet_image_should_be_created(self):
        return self.status == Statuses.PUBLISH

    class Meta:
        verbose_name = 'example object'
        verbose_name_plural = 'example objects'

And use in template:

<meta property="og:image" content="{{ instance.snippet_image_field.url }}" />

Read more on home page.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-snippet-image, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size django_snippet_image-0.1.3-py3-none-any.whl (6.7 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size django-snippet-image-0.1.3.tar.gz (5.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page